This repository has been archived by the owner on Apr 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathconfigure_system.sh
322 lines (281 loc) · 16.2 KB
/
configure_system.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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/usr/bin/env bash
###############################################################
### Anarchy Linux Install Script
### configure_system.sh
###
### Copyright (C) 2017 Dylan Schacht
###
### By: Dylan Schacht (deadhead)
### Email: [email protected]
### Webpage: https://anarchylinux.org
###
### Any questions, comments, or bug reports may be sent to above
### email address. Enjoy, and keep on using Arch.
###
### License: GPL v2.0
###############################################################
configure_system() {
op_title="$config_op_msg"
if [ "$bootloader" == "syslinux" ] || [ "$bootloader" == "systemd-boot" ] && "$UEFI" ; then
if [ "$esp_mnt" != "/boot" ]; then
(mkdir "$ARCH"/etc/pacman.d/hooks
if [ "$kernel" == "linux" ]; then
echo -e "$linux_hook\nExec = /usr/bin/cp /boot/{vmlinuz-linux,initramfs-linux.img,initramfs-linux-fallback.img} ${esp_mnt}" > "$ARCH"/etc/pacman.d/hooks/linux-esp.hook
cp "$ARCH"/boot/{vmlinuz-linux,initramfs-linux.img,initramfs-linux-fallback.img} ${ARCH}${esp_mnt}
elif [ "$kernel" == "linux-lts" ]; then
echo -e "$lts_hook\nExec = /usr/bin/cp /boot/{vmlinuz-linux-lts,initramfs-linux-lts.img,initramfs-linux-lts-fallback.img} ${esp_mnt}" > "$ARCH"/etc/pacman.d/hooks/linux-esp.hook
cp "$ARCH"/boot/{vmlinuz-linux-lts,initramfs-linux-lts.img,initramfs-linux-lts-fallback.img} ${ARCH}${esp_mnt}
elif [ "$kernel" == "linux-hardened" ]; then
echo -e "$hardened_hook\nExec = /usr/bin/cp /boot/{vmlinuz-linux-hardened,initramfs-linux-hardened.img,initramfs-linux-hardened-fallback.img} ${esp_mnt}" > "$ARCH"/etc/pacman.d/hooks/linux-esp.hook
cp "$ARCH"/boot/{vmlinuz-linux-hardened,initramfs-linux-hardened.img,initramfs-linux-hardened-fallback.img} ${ARCH}${esp_mnt}
elif [ "$kernel" == "linux-zen" ]; then
echo -e "$zen_hook\nExec = /usr/bin/cp /boot/{vmlinuz-linux-zen,initramfs-linux-zen.img,initramfs-linux-zen-fallback.img} ${esp_mnt}" > "$ARCH"/etc/pacman.d/hooks/linux-esp.hook
cp "$ARCH"/boot/{vmlinuz-linux-zen,initramfs-linux-zen.img,initramfs-linux-zen-fallback.img} ${ARCH}${esp_mnt}
fi) &
pid=$! pri=0.1 msg="$wait_load \n\n \Z1> \Z2cp "$ARCH"/boot/ ${ARCH}${esp_mnt}\Zn" load
fi
fi
if "$drm" ; then
sed -i '/^MODULES=/ s/.$/ nvidia nvidia_modeset nvidia_uvm nvidia_drm )/;s/" /"/'
sed -i 's!FILES=""!FILES="/etc/modprobe.d/nvidia.conf"!' "$ARCH"/etc/mkinitcpio.conf
echo "options nvidia_drm modeset=1" > "$ARCH"/etc/modprobe.d/nvidia.conf
if (<<<"$GPU" grep "nvidia" &> /dev/null); then
echo "blacklist nouveau" >> "$ARCH"/etc/modprobe.d/nvidia.conf
fi
if [ ! -d "$ARCH"/etc/pacman.d/hooks ]; then
mkdir "$ARCH"/etc/pacman.d/hooks
fi
echo -e "$nvidia_hook\nExec=/usr/bin/mkinitcpio -p $kernel" > "$ARCH"/etc/pacman.d/hooks/nvidia.hook
if ! "$crypted" && ! "$enable_f2fs" ; then
arch-chroot "$ARCH" mkinitcpio -p "$kernel" &>/dev/null &
pid=$! pri=1 msg="\n$kernel_config_load \n\n \Z1> \Z2mkinitcpio -p $kernel\Zn" load
fi
echo "$(date -u "+%F %H:%M") : Enable nvidia drm" >> "$log"
fi
if "$enable_f2fs" ; then
sed -i '/^MODULES=/ s/.$/ f2fs crc32 libcrc32c crc32c_generic crc32c-intel crc32-pclmul )/;s/" /"/' "$ARCH"/etc/mkinitcpio.conf
if ! "$crypted" ; then
arch-chroot "$ARCH" mkinitcpio -p "$kernel" &>/dev/null &
pid=$! pri=1 msg="\n$f2fs_config_load \n\n \Z1> \Z2mkinitcpio -p $kernel\Zn" load
fi
echo "$(date -u "+%F %H:%M") : Configure system for f2fs" >> "$log"
fi
if "$enable_xfs" ; then
sed -i '/^MODULES=/ s/.$/ xfs )/;s/" /"/' "$ARCH"/etc/mkinitcpio.conf
if ! "$crypted" ; then
arch-chroot "$ARCH" mkinitcpio -p "$kernel" &>/dev/null &
pid=$! pri=1 msg="\n$xfs_config_load \n\n \Z1> \Z2mkinitcpio -p $kernel\Zn" load
fi
echo "$(date -u "+%F %H:%M") : Configure system for xfs" >> "$log"
fi
if (<<<"$BOOT" egrep "nvme.*" &> /dev/null) then
sed -i '/^MODULES=/ s/.$/ nvme )/;s/" /"/' "$ARCH"/etc/mkinitcpio.conf
if ! "$crypted" ; then
arch-chroot "$ARCH" mkinitcpio -p "$kernel" &>/dev/null &
pid=$! pri=1 msg="\n$kernel_config_load \n\n \Z1> \Z2mkinitcpio -p $kernel\Zn" load
fi
echo "$(date -u "+%F %H:%M") : Configure system for nvme" >> "$log"
fi
if "$crypted" && "$UEFI" ; then
echo "/dev/$BOOT $esp_mnt vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 2" > "$ARCH"/etc/fstab
elif "$crypted" ; then
echo "/dev/$BOOT /boot ext4 defaults 0 2" > "$ARCH"/etc/fstab
fi
if "$crypted" ; then
(echo "/dev/mapper/root / $FS defaults 0 1" >> "$ARCH"/etc/fstab
echo "/dev/mapper/tmp /tmp tmpfs defaults 0 0" >> "$ARCH"/etc/fstab
echo "tmp /dev/lvm/tmp /dev/urandom tmp,cipher=aes-xts-plain64,size=256" >> "$ARCH"/etc/crypttab
if "$SWAP" ; then
echo "/dev/mapper/swap none swap sw 0 0" >> "$ARCH"/etc/fstab
echo "swap /dev/lvm/swap /dev/urandom swap,cipher=aes-xts-plain64,size=256" >> "$ARCH"/etc/crypttab
fi
sed -i 's/HOOKS=.*/HOOKS="base udev autodetect keyboard keymap consolefont modconf block encrypt lvm2 filesystems fsck"/' "$ARCH"/etc/mkinitcpio.conf
arch-chroot "$ARCH" mkinitcpio -p "$kernel") &> /dev/null &
pid=$! pri=1 msg="\n$encrypt_load1 \n\n \Z1> \Z2mkinitcpio -p $kernel\Zn" load
echo "$(date -u "+%F %H:%M") : Configure system for encryption" >> "$log"
else
(sed -i 's/HOOKS=.*/HOOKS="base udev autodetect keyboard keymap consolefont modconf block lvm2 filesystems fsck"/' "$ARCH"/etc/mkinitcpio.conf
arch-chroot "$ARCH" mkinitcpio -p "$kernel") &> /dev/null &
pid=$! pri=1 msg="\n$kernel_config_load \n\n \Z1> \Z2mkinitcpio -p $kernel\Zn" load
echo "$(date -u "+%F %H:%M") : Configure system with the default mkinitcpio hooks" >> "$log"
fi
(sed -i -e "s/#$LOCALE/$LOCALE/" "$ARCH"/etc/locale.gen
echo LANG="$LOCALE" > "$ARCH"/etc/locale.conf
arch-chroot "$ARCH" locale-gen) &> /dev/null &
pid=$! pri=0.1 msg="\n$locale_load_var \n\n \Z1> \Z2LANG=$LOCALE ; locale-gen\Zn" load
echo "$(date -u "+%F %H:%M") : Set system locale: $LOCALE" >> "$log"
if [ "$keyboard" != "$default" ]; then
echo "KEYMAP=$keyboard" > "$ARCH"/etc/vconsole.conf
if "$desktop" ; then
echo -e "Section \"InputClass\"\nIdentifier \"system-keyboard\"\nMatchIsKeyboard \"on\"\nOption \"XkbLayout\" \"$keyboard\"\nEndSection" > "$ARCH"/etc/X11/xorg.conf.d/00-keyboard.conf
arch-chroot "$ARCH" localectl set-x11-keymap $keyboard &>/dev/null
fi
echo "$(date -u "+%F %H:%M") : Set system keymap: $keyboard" >> "$log"
fi
(arch-chroot "$ARCH" ln -sf /usr/share/zoneinfo/"$ZONE" /etc/localtime ; sleep 0.5) &
pid=$! pri=0.1 msg="\n$zone_load_var \n\n \Z1> \Z2ln -sf $ZONE /etc/localtime\Zn" load
echo "$(date -u "+%F %H:%M") : Set system timezone: $ZONE" >> "$log"
case "$net_util" in
networkmanager) arch-chroot "$ARCH" systemctl enable NetworkManager.service &>/dev/null
pid=$! pri=0.1 msg="\n$nwmanager_msg0 \n\n \Z1> \Z2systemctl enable NetworkManager.service\Zn" load
echo "$(date -u "+%F %H:%M") : Enable networkmanager" >> "$log"
;;
netctl) arch-chroot "$ARCH" systemctl enable netctl.service &>/dev/null &
pid=$! pri=0.1 msg="\n$nwmanager_msg1 \n\n \Z1> \Z2systemctl enable netctl.service\Zn" load
echo "$(date -u "+%F %H:%M") : Enable netctl" >> "$log"
;;
esac
if "$enable_bt" ; then
arch-chroot "$ARCH" systemctl enable bluetooth &>/dev/null &
pid=$! pri=0.1 msg="\n$btenable_msg \n\n \Z1> \Z2systemctl enable bluetooth.service\Zn" load
echo "$(date -u "+%F %H:%M") : Enable bluetooth" >> "$log"
fi
if "$desktop" ; then
if [ "$start_term" == "sway" ]; then
mkdir -p "$ARCH"/etc/skel/.config/sway/
cp "$ARCH"/etc/sway/config "$ARCH"/etc/skel/.config/sway/config
else
echo "$start_term" > "$ARCH"/etc/skel/.xinitrc
echo "$start_term" > "$ARCH"/root/.xinitrc
echo "$(date -u "+%F %H:%M") : Create xinitrc: $start_term" >> "$log"
fi
fi
if "$enable_dm" ; then
arch-chroot "$ARCH" systemctl enable "$DM".service &> /dev/null &
pid=$! pri="0.1" msg="$wait_load \n\n \Z1> \Z2systemctl enable "$DM"\Zn" load
echo "$(date -u "+%F %H:%M") : Enable $DM" >> "$log"
fi
if "$VM" ; then
case "$virt" in
vbox) arch-chroot "$ARCH" systemctl enable vboxservice.service &>/dev/null &
pid=$! pri=0.1 msg="\n$vbox_enable_msg \n\n \Z1> \Z2systemctl enable vboxservice\Zn" load
echo "$(date -u "+%F %H:%M") : Enable vboxservice" >> "$log"
;;
vmware) (cat "$ARCH"/proc/version > "$ARCH"/etc/arch-release
arch-chroot "$ARCH" systemctl enable vmtoolsd.service
arch-chroot "$ARCH" systemctl enable vmware-vmblock-fuse.service
mkdir "$ARCH"/etc/init.d
for x in {0..6}; do mkdir -p "$ARCH"/etc/init.d/rc${x}.d; done) &>/dev/null &
pid=$! pri=0.1 msg="\n$vbox_enable_msg \n\n \Z1> \Z2systemctl enable vmtoolsd\Zn" load
echo "$(date -u "+%F %H:%M") : Enable vmware" >> "$log"
;;
esac
fi
if "$desktop"; then
config_env &
pid=$! pri="0.1" msg="$wait_load \n\n \Z1> \Z2anarchy configure desktop\Zn" load
if [ "$DM" == "lightdm" ]; then
cp -r "${anarchy_directory}"/extra/desktop/lightdm/lightdm-gtk-greeter.conf "$ARCH"/etc/lightdm/
fi
fi
#if "$add_repo" ; then
#echo -e "\n[anarchy]\nServer = $aa_repo\nSigLevel = Never" >> "$ARCH"/etc/pacman.conf
#fi
if "$multilib" ; then
sed -i '/\[multilib]$/ {
N
/Include/s/#//g}' "$ARCH"/etc/pacman.conf
echo "$(date -u "+%F %H:%M") : Include multilib" >> "$log"
fi
if "$aa_repo" ; then
sed -i -e '$a\\n[anarchy]\nServer = https://anarchylinux.org/repo/x86_64\nSigLevel = Never' "$ARCH"/etc/pacman.conf
fi
if "$dhcp" ; then
arch-chroot "$ARCH" systemctl enable dhcpcd.service &>/dev/null &
pid=$! pri=0.1 msg="\n$dhcp_load \n\n \Z1> \Z2systemctl enable dhcpcd\Zn" load
echo "$(date -u "+%F %H:%M") : Enable dhcp" >> "$log"
fi
if "$enable_ssh" ; then
arch-chroot "$ARCH" systemctl enable sshd.service &>/dev/null &
pid=$! pri=0.1 msg="\n$ssh_load \n\n \Z1> \Z2systemctl enable sshd\Zn" load
echo "$(date -u "+%F %H:%M") : Enable ssh" >> "$log"
fi
if "$enable_ftp" ; then
arch-chroot "$ARCH" systemctl enable ${ftp}.service &>/dev/null &
pid=$! pri=0.1 msg="\n$ftp_load \n\n \Z1> \Z2systemctl enable ${ftp}\Zn" load
echo "$(date -u "+%F %H:%M") : Enable $ftp" >> "$log"
fi
if "$enable_cups" ; then
arch-chroot "$ARCH" systemctl enable org.cups.cupsd.service &>/dev/null &
pid=$! pri=0.1 msg="\n$cups_load \n\n \Z1> \Z2systemctl enable cups\Zn" load
echo "$(date -u "+%F %H:%M") : Enable cups" >> "$log"
fi
### Enable cpupower
arch-chroot "$ARCH" systemctl enable cpupower.service
pid=$! pri=0.1 msg="\n$cups_load \n\n \Z1> \Z2systemctl enable cpupower\Zn" load
echo "$(date -u "+%F %H:%M") : Enable cpupower" >> "$log"
if "$enable_http" ; then
case "$config_http" in
"LAMP")
(arch-chroot "$ARCH" systemctl enable httpd.service
sed -i 's!LoadModule mpm_event_module modules/mod_mpm_event.so!LoadModule mpm_prefork_module modules/mod_mpm_prefork.so!' "$ARCH"/etc/httpd/conf/httpd.conf
tac "$ARCH"/etc/httpd/conf/httpd.conf | awk '!p && /LoadModule/{print "AddHandler php7-script php\nLoadModule php7_module modules/libphp7.so\n# PHP Modules\n"; p=1} 1' | tac > "$ARCH"/etc/httpd/conf/httpd.conf.bak
tac "$ARCH"/etc/httpd/conf/httpd.conf | awk '!p && /Include/{print "\nInclude conf/extra/php7_module.conf\n# PHP Modules\n"; p=1} 1' | tac > "$ARCH"/etc/httpd/conf/httpd.conf.bak
cp "$ARCH"/etc/httpd/conf/httpd.conf.bak "$ARCH"/etc/httpd/conf/httpd.conf
sed -i 's/;extension=pdo_mysql.so/extension=pdo_mysql.so/' "$ARCH"/etc/php/php.ini) &>/dev/null &
pid=$! pri=0.1 msg="\n$http_load \n\n \Z1> \Z2configure LAMP stack\Zn" load
;;
"LEMP")
(arch-chroot "$ARCH" systemctl enable nginx.service
arch-chroot "$ARCH" systemctl enable php-fpm.service) &>/dev/null &
pid=$! pri=0.1 msg="\n$http_load \n\n \Z1> \Z2configure LEMP stack\Zn" load
;;
"apache")
arch-chroot "$ARCH" systemctl enable httpd.service &>/dev/null &
pid=$! pri=0.1 msg="\n$http_load \n\n \Z1> \Z2systemctl enable httpd\Zn" load
;;
"nginx")
arch-chroot "$ARCH" systemctl enable nginx.service &>/dev/null &
pid=$! pri=0.1 msg="\n$http_load \n\n \Z1> \Z2systemctl enable nginx\Zn" load
;;
esac
fi
if [ -f "$ARCH"/var/lib/pacman/db.lck ]; then
rm "$ARCH"/var/lib/pacman/db.lck &> /dev/null
fi
arch-chroot "$ARCH" pacman -Sy &> /dev/null &
pid=$! pri=0.8 msg="\n$pacman_load \n\n \Z1> \Z2pacman -Sy\Zn" load
echo "$(date -u "+%F %H:%M") : Updated pacman databases" >> "$log"
if [ "$sh" == "/bin/bash" ]; then
cp "$ARCH"/etc/skel/.bash_profile "$ARCH"/root/
elif [ "$sh" == "/usr/bin/zsh" ]; then
if [ "$shrc" == "$default" ]; then
cp "${anarchy_directory}"/extra/.zshrc "$ARCH"/root/.zshrc
cp "${anarchy_directory}"/extra/.zshrc "$ARCH"/etc/skel/.zshrc
elif [ "$shrc" == "oh-my-zsh" ]; then
cp "${anarchy_directory}"/extra/.zshrc-oh-my "$ARCH"/root/.zshrc
cp "${anarchy_directory}"/extra/.zshrc-oh-my "$ARCH"/etc/skel/.zshrc
elif [ "$shrc" == "grml-zsh-config" ]; then
cp "${anarchy_directory}"/extra/.zshrc-grml "$ARCH"/root/.zshrc
cp "${anarchy_directory}"/extra/.zshrc-grml "$ARCH"/etc/skel/.zshrc
else
touch "$ARCH"/root/.zshrc
touch "$ARCH"/etc/skel/.zshrc
fi
elif [ "$shell" == "fish" ]; then
echo "exec fish" >> "${anarchy_directory}"/extra/.bashrc-root
echo "exec fish" >> "${anarchy_directory}"/extra/.bashrc
elif [ "$shell" == "tcsh" ]; then
cp "${anarchy_directory}"/extra/{.tcshrc,.tcshrc.conf} "$ARCH"/root/
cp "${anarchy_directory}"/extra/{.tcshrc,.tcshrc.conf} "$ARCH"/etc/skel/
elif [ "$shell" == "mksh" ]; then
cp "${anarchy_directory}"/extra/.mkshrc "$ARCH"/root/
cp "${anarchy_directory}"/extra/.mkshrc "$ARCH"/etc/skel/
fi
cp "${anarchy_directory}"/extra/.bashrc-root "$ARCH"/root/.bashrc
cp "${anarchy_directory}"/extra/.bashrc "$ARCH"/etc/skel/
sed -i 's/^#Color$/Color/' "$ARCH"/etc/pacman.conf
sed -i 's/^#TotalDownload$/TotalDownload/' "$ARCH"/etc/pacman.conf
sed -i 's/^#CheckSpace$/CheckSpace/' "$ARCH"/etc/pacman.conf
sed -i 's/^#VerbosePkgLists$/VerbosePkgLists/' "$ARCH"/etc/pacman.conf
sed -i '/^VerbosePkgLists$/ a ILoveCandy' "$ARCH"/etc/pacman.conf
echo "$hostname" > "$ARCH"/etc/hostname
echo "$(date -u "+%F %H:%M") : Hostname set: $hostname" >> "$log"
arch-chroot "$ARCH" chsh -s "$sh" &>/dev/null
input="$(echo "$root_crypt" | openssl enc -aes-256-cbc -a -d -salt -pass pass:"$ssl_key")"
(sleep 1 ; printf "$input\n$input" | arch-chroot "$ARCH" passwd root) &> /dev/null &
pid=$! pri=0.1 msg="$wait_load \n\n \Z1> \Z2passwd root\Zn" load
unset input
echo "$(date -u "+%F %H:%M") : Password set: root" >> "$log"
}
# vim: ai:ts=4:sw=4:et