-
Notifications
You must be signed in to change notification settings - Fork 2
/
post_chroot.sh
executable file
·268 lines (228 loc) · 9.17 KB
/
post_chroot.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#!/bin/sh
SCRIPT_DIR="$(realpath "$(dirname "${0}")")"
CONFIG_FILE="${SCRIPT_DIR}/install.config"
. "${SCRIPT_DIR}/config/shell-utils/util.sh"
PACKAGES="ranger
man-db
man-pages
texinfo
wget
networkmanager
network-manager-applet
ntp
bluez
bluez-utils
gnome-keyring
seahorse
ttf-fira-code
noto-fonts
noto-fonts-cjk
noto-fonts-emoji
noto-fonts-extra
pulseaudio
pulseaudio-bluetooth
alsa-utils
pavucontrol
pasystray
grub
efibootmgr
os-prober
base-devel
git
i3lock
dmenu
feh
xss-lock
openssl
brightnessctl
"
CUSTOM_PACKAGES="vim
xorg
i3
i3status
ly
kitty
picom
ssh
zsh
docker
notification_daemon
"
AUR_PACKAGES="google-chrome
"
AUR_PKG_INSTALL_USER='aurpkginstalluser'
setup_hostname() {(
set -e
local hostname_regex='^hostname[ \t]*=[ \t]*[[:alnum:]]+$'
local hname=$(grep -E "${hostname_regex}" "${CONFIG_FILE}" | sed 's/.*=[ \t]*//')
echo "${hname}" > /etc/hostname
echo '127.0.0.1 localhost' >/etc/hosts
echo '::1 localhost' >>/etc/hosts
echo "127.0.1.1 ${hname}.localdomain ${hname}" >>/etc/hosts
)}
setup_root_user() {
local root_pass_regex='^root_pass[ \t]*=[ \t]*.+$'
local pass=$(grep -E "${root_pass_regex}" "${CONFIG_FILE}" | sed 's/.*=[ \t]*//')
usermod -p "$(openssl passwd -6 "${pass}")" root
}
setup_users() {
local user_regex='^user[ \t]*=[ \t]*[[:alnum:]]+:.+:[0|1]$'
local users=$(grep -E "${user_regex}" "${CONFIG_FILE}" | sed 's/.*=[ \t]*//')
for user in ${users}; do
local username="$(echo ${user} | cut -d ':' -f1)"
local password="$(echo ${user} | grep -o -E ':.*:' | sed 's/^:\(.*\):$/\1/')"
local issudoer="$(echo ${user} | grep -o -E '[1|0]$')"
useradd -m "${username}"
usermod -p "$(openssl passwd -6 "${password}")" "${username}"
if [ ${issudoer} -eq 1 ]; then
echo 'Defaults targetpw' >"/etc/sudoers.d/${username}"
echo "${username} ALL=(ALL) ALL" >>"/etc/sudoers.d/${username}"
fi
mkdir -p "/home/${username}/Pictures/wallpapers"
cd "/home/${username}/Pictures/wallpapers"
wget 'https://unsplash.com/photos/GNQUsuajHFQ/download?force=true&w=1920' -O 1
wget 'https://unsplash.com/photos/k6BHLfw_jUg/download?force=true&w=1920' -O 2
wget 'https://unsplash.com/photos/KMrYZp6ismc/download?force=true&w=1920' -O 3
wget 'https://unsplash.com/photos/gULJzSnDuZU/download?force=true&w=1920' -O 4
wget 'https://unsplash.com/photos/EhSxbBCjr9A/download?force=true&w=1920' -O 5
wget 'https://unsplash.com/photos/YaVzA1txTRQ/download?force=true&w=1920' -O 6
wget 'https://unsplash.com/photos/JwqUV94sK74/download?force=true&w=1920' -O 7
wget 'https://unsplash.com/photos/DzqcXxUh61M/download?force=true&w=1920' -O 8
wget 'https://unsplash.com/photos/BMO1SzQHWRs/download?force=true&w=1920' -O 9
wget 'https://unsplash.com/photos/xJ5HgOc28Os/download?force=true&w=1920' -O 10
wget 'https://unsplash.com/photos/Z2s0-zSe3TI/download?force=true&w=1920' -O 11
cd -
chown -R "${username}":"${username}" "/home/${username}/Pictures"
mkdir -p "/home/${username}/Work"
chown -R "${username}":"${username}" "/home/${username}/Work"
for package in ${CUSTOM_PACKAGES}; do
install_custom_package_config "${package}" "${username}"
done
"${SCRIPT_DIR}/config/fix_owner.sh" "${username}"
done
}
pre_install_aur_packages() {
# I need a regular user that can elevate to root
# through sudo so I can install AUR packages through
# makepkg command
useradd "${AUR_PKG_INSTALL_USER}"
echo "${AUR_PKG_INSTALL_USER} ALL=(ALL) NOPASSWD:ALL" >"/etc/sudoers.d/${AUR_PKG_INSTALL_USER}"
}
post_install_aur_packages() {
userdel "${AUR_PKG_INSTALL_USER}"
rm "/etc/sudoers.d/${AUR_PKG_INSTALL_USER}"
}
setup_timezone() {
ln -sf /usr/share/zoneinfo/Europe/Bucharest /etc/localtime &&
hwclock --systohc &&
systemctl enable ntpd.service
}
setup_localization() {
sed -i 's/^#\(en_US.UTF-8 UTF-8\)/\1/' /etc/locale.gen &&
locale-gen &&
echo 'LANG=en_US.UTF-8' >/etc/locale.conf
}
install_package() {
local package_name="${1}"
pacman -S --noconfirm "${package_name}"
}
install_custom_package() {
local package_name="${1}"
"${SCRIPT_DIR}/config/make.sh" install "${package_name}"
}
install_custom_package_config() {
local package_name="${1}"
local username="${2}"
"${SCRIPT_DIR}/config/make_config.sh" install "${package_name}" "${username}"
}
install_aur_package() {
local aur_package_name="$1"
git clone "https://aur.archlinux.org/${aur_package_name}.git" "${aur_package_name}" &&
chown -R ${AUR_PKG_INSTALL_USER}:${AUR_PKG_INSTALL_USER} "./${aur_package_name}" &&
cd "./${aur_package_name}" &&
su ${AUR_PKG_INSTALL_USER} --command="makepkg -s --noconfirm" &&
pacman -U --noconfirm *.pkg.tar.*
local ret=$?
cd -
rm -rf "${aur_package_name}"
return ${ret}
}
intel_integrated_graphics() {
lspci -v | grep VGA | grep -i intel
}
nvidia_dedicated_graphics() {
lspci -v | grep -e VGA -e 3D | grep -i nvidia
}
amd_dedicated_graphics() {
lspci -v | grep -e VGA -e 3D | grep -i amd
}
install_amd_gpu_drivers() {
perform_task_arg install_package xf86-video-amdgpu 'Installing amd driver for dedicated graphics ' &&
perform_task_arg install_package mesa 'Installing package mesa ' &&
perform_task_arg install_package libva-mesa-driver 'Installling libva-mesa-driver '
}
enable_ucode_updates() {
if [ -n "$(lscpu | grep Vendor | grep -i intel)" ]; then
install_package intel-ucode
elif [ -n "$(lscpu | grep Vendor | grep -i amd)" ]; then
install_package amd-ucode
fi
}
install_grub_bootloader() {
print_msg '--------------------------------\n'
print_msg 'Installing grub boot-loader\n'
print_msg '--------------------------------\n'
grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=GRUB &&
grub-mkconfig -o /boot/grub/grub.cfg >$(tty) 2>&1 &&
print_msg '-------------SUCCESS------------\n' ||
print_msg '-------------FAILED-------------\n'
}
enable_network_manager() {
systemctl enable NetworkManager.service
}
enable_bluetooth() {
systemctl enable bluetooth.service
}
configure_gnome_keyring() {
local last_auth_entry=$(grep --line-number -E "^auth" /etc/pam.d/login | tail -n 1 | sed 's/\([0-9]\+\):.*/\1/')
sed -i "${last_auth_entry} s/^\(auth.*\)/&\nauth\toptional\tpam_gnome_keyring.so/" /etc/pam.d/login
local last_session_entry=$(grep --line-number -E "^session" /etc/pam.d/login | tail -n 1 | sed 's/\([0-9]\+\):.*/\1/')
sed -i "${last_session_entry} s/^\(session.*\)/&\nsession\toptional\tpam_gnome_keyring.so auto_start/" /etc/pam.d/login
}
main() {
if [ -t 1 ]; then
print_msg "ERR: Run ./install.sh instead. Check readme for more details on how to use the installer.\n"
return 1
fi
if [ ! -f "${CONFIG_FILE}" ]; then
print_msg "ERR: Missing config file. Check readme for more details on how to use the installer.\n"
return 2
fi
for package in ${PACKAGES}; do
perform_task_arg install_package "${package}" "Installing package ${package}"
done
for package in ${CUSTOM_PACKAGES}; do
perform_task_arg install_custom_package "${package}"
done
perform_task setup_hostname 'Setting up hostname'
perform_task setup_root_user 'Setting up root user'
perform_task setup_users 'Setting up users'
perform_task setup_timezone 'Setting up timezone '
perform_task setup_localization 'Setting up localization '
perform_task pre_install_aur_packages 'Setting up prerequisites to install AUR packages'
for package in ${AUR_PACKAGES}; do
perform_task_arg install_aur_package ${package} "Installing AUR package ${package} "
done
perform_task post_install_aur_packages 'Tearing down prerequisites for AUR packages'
intel_integrated_graphics && perform_task_arg install_package xf86-video-intel "Installing intel driver for integrated graphics "
nvidia_dedicated_graphics && perform_task_arg install_package nvidia "Installing nvidia driver for dedicated graphics "
nvidia_dedicated_graphics && intel_integrated_graphics && perform_task_arg install_package nvidia-prime "Instaling nvidia prime (for optimus technology) "
amd_dedicated_graphics && install_amd_gpu_drivers
perform_task enable_network_manager 'Enabling Network Manager'
perform_task enable_bluetooth 'Enabling Bluetooth'
perform_task configure_gnome_keyring 'Enabling sensitive information encryption through gnome keyring '
perform_task enable_ucode_updates 'Enabling ucode updates '
install_grub_bootloader
check_for_errors
}
main "${@}"