-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·411 lines (357 loc) · 12.5 KB
/
install.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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
#!/bin/bash
format_disks(){
if [[ -z $parts ]]; then
get_partitions
let partcount=$(echo $parts | wc -w)
let partcount+=1
fi
# Generate whiptail menu command for partition formatting
partmenu="whiptail --menu --noitem \"Pick a partition to format\" 15 40 $partcount"
for x in $parts; do
partmenu="$partmenu \"$x\" \"\""
done
partmenu="$partmenu \"done\" \"\""
# Ask user for formatting preferences until done or cancel are selected
partmenuchoice=$(eval $partmenu 3>&1 1>&2 2>&3)
while [[ $partmenuchoice != "done" && $partmenuchoice != "" ]]; do
fs=$(whiptail --menu --noitem "How would you like to format $partmenuchoice?" 13 45 5 "ext2" "" "ext3" "" "ext4" "" "vfat" "" "xfs" "" "btrfs" "" 3>&1 1>&2 2>&3)
if [[ $fs != "" ]]; then
eval "mkfs.$fs $partmenuchoice"
fi
partmenuchoice=$(eval $partmenu 3>&1 1>&2 2>&3)
done
}
setup_swap(){
if [[ -z $parts ]]; then
get_partitions
let partcount=$(echo $parts | wc -w)
let partcount+=1
fi
# Generate swap menu command
swapmenu="whiptail --menu --noitem \"Pick a partition to use as swap\" 15 35 $partcount"
for x in $parts; do
swapmenu="$swapmenu \"$x\" \"\""
done
swapmenu="$swapmenu \"no swap\" \"\""
# Format swap partition if present
swapmenuchoice=$(eval $swapmenu 3>&1 1>&2 2>&3)
if [[ $swapmenuchoice != "done" && $swapmenuchoice != "" ]]; then
mkswap $swapmenuchoice
swapon $swapmenuchoice
fi
}
mount_partitions(){
if [[ -z $parts ]]; then
get_partitions
let partcount=$(echo $parts | wc -w)
let partcount+=1
fi
# Generate partition mounting menu
mountmenu="whiptail --menu --noitem \"Pick a partition to mount\" 15 40 $partcount"
for x in $parts; do
mountmenu="$mountmenu \"$x\" \"\""
done
mountmenu="$mountmenu \"done\" \"\""
# Mount disk partitions
mountmenuchoice=$(eval $mountmenu 3>&1 1>&2 2>&3)
while [[ $mountmenuchoice != "done" && $mountmenuchoice != "" ]]; do
location=$(whiptail --inputbox "Where would you like to mount $mountmenuchoice?" 10 45 3>&1 1>&2 2>&3)
if [[ $location != "" ]]; then
if [ ${location:0:4} == "/mnt" ]; then
if [ ! -d $location]; then
mkdir $location
fi
mount $mountmenuchoice $location
else
if [ ! -d "/mnt/$location" ]; then
mkdir /mnt/$location
fi
mount $mountmenuchoice /mnt/$location
fi
fi
mountmenuchoice=$(eval $mountmenu 3>&1 1>&2 2>&3)
done
}
set_hostname(){
hostname=$(whiptail --inputbox "Please enter a hostname for the new system" 10 46 3>&1 1>&2 2>&3)
echo $hostname > /mnt/etc/hostname
}
setup_network(){
wifi=$(whiptail --yesno "Are you going to use wifi?" 7 31 3>&1 1>&2 2>&3)
if [[ $wifi == "yes" ]]; then
arch-chroot /mnt pacman -S wpa_supplicant iw dialog
fi
dhcp=$(whiptail --yesno "Would you like to use DHCP?" 7 31 3>&1 1>&2 2>&3)
if [[ $dhcp == "yes" ]]; then
arch-chroot /mnt systemctl enable dhcpcd
fi
}
set_timezone(){
# construct command string for time region
timemenu="whiptail --menu \"Select a region\" 25 50 15"
for region in $(ls /usr/share/zoneinfo | xargs); do
if [[ -d /usr/share/zoneinfo/$region ]]; then
timemenu="$timemenu \"$region\" \"\""
fi
done
region=$(eval $timemenu 3>&1 1>&2 2>&3)
# if user did not cancel construct command string for time zone
if [[ $region != "" ]]; then
submenu="whiptail --menu \"Select a timezone\" 25 50 15"
for zone in $(ls /usr/share/zoneinfo/$region | xargs); do
submenu="$submenu \"$zone\" \"\""
done
zone=$(eval $submenu 3>&1 1>&2 2>&3)
# if user did not cancel set timezone
if [[ $zone != "" ]]; then
# if this is a directory there is a subzone
if [[ -d /usr/share/zoneinfo/$region/$zone ]]; then
subzonemenu="whiptail --menu \"Select a subzone\" 25 50 15"
for subzone in $(ls /usr/share/zoneinfo/$region/$zone/ | xargs); do
subzonemenu="$subzonemenu \"$subzone\" \"\""
done
subzone=$(eval $subzonemenu 3>&1 1>&2 2>&3)
if [[ $subzone != "" ]]; then
ln -sf /usr/share/zoneinfo/$region/$zone/$subzone /etc/localtime
fi
fi
else # there is no subzone
arch-chroot /mnt ln -sf /usr/share/zoneinfo/$region/$zone /etc/localtime
fi
fi
}
set_locale(){
localemenu="whiptail --menu --noitem \"Please select the locale you want to use\" 25 50 15"
for line in $(seq 24 484); do
localemenu="$localemenu \"$(head -n $line /mnt/etc/locale.gen | tail -n 1 | sed "s/#//")\" \"\""
done
locale=$(eval $localemenu 3>&1 1>&2 2>&3 | cut -d " " -f 1)
if [[ $locale != "" ]]; then
# get line number in /etc/locale.gen
line=$(grep -n $locale /mnt/etc/locale.gen | cut -d : -f 1 | tail -n 1)
# uncomment said line
sed -i"" "$line s/#//" /mnt/etc/locale.gen
arch-chroot /mnt locale-gen
echo "LANG=$(grep -e "^[^#]" /mnt/etc/locale.gen | awk '{print $1}')" > /mnt/etc/locale.conf
fi
}
# TODO: fix the cancel logic so that blank entries dont cancel but button presses do
# Try to use exit status as a way to check if the cancel button is pressed "$?"
set_root_passwd(){
pass1=" "
pass2=" "
while [[ $pass1 != $pass2 && ! -z $pass1 && ! -z $pass2 ]]; do
pass1=$(whiptail --passwordbox "Enter the password you wish to use for root" 10 50 3>&1 1>&2 2>&3)
pass2=$(whiptail --passwordbox "Enter the password again" 10 50 3>&1 1>&2 2>&3)
if [[ $pass1 != $pass2 && ! -z $pass1 && ! -z $pass2 ]]; then
whiptail --msgbox "Passwords do not match please try again" 10 50
elif [[ $pass1 == "" && $pass2 == "" ]]; then
whiptail --msgbox "Password cannot be blank please try again" 10 50
pass1=" "
pass2=" "
elif [[ $pass1 == $pass2 ]]; then
echo "echo \"root:$pass1\" | chpasswd" > /mnt/changeroot.sh
arch-chroot /mnt chmod +x changeroot.sh
arch-chroot /mnt ./changeroot.sh
arch-chroot /mnt rm changeroot.sh
fi
done
}
# TODO: update password flow control to satisfy same problems as set_root_passwd
add_user(){
user=$(whiptail --inputbox "Enter a new username" 10 50 3>&1 1>&2 2>&3)
if [[ $user != "" ]]; then
groups=$(whiptail --inputbox "Enter any secondary groups you would like the new user to be in, seperated by comma" 15 50 3>&1 1>&2 2>&3)
if [[ $groups != "" ]]; then
arch-chroot /mnt useradd -m -G $groups $user
else
arch-chroot /mnt useradd -m $user
fi
pass1="default1"
pass2="default2"
while [[ $pass1 != $pass2 || $pass1 == "" ]]; do
pass1=$(whiptail --passwordbox "Please enter a password for user $user" 10 50 3>&1 1>&2 2>&3)
pass2=$(whiptail --passwordbox "Please enter again" 10 50 3>&1 1>&2 2>&3)
if [[ $pass1 != $pass2 ]]; then
whiptail --msgbox "Passwords do no match please try again" 10 50
elif [[ $pass1 == "" ]]; then
whiptail --msgbox "Password cannot be blank please try again" 10 50
else
echo "echo \"$user:$pass1\" | chpasswd" > /mnt/changepass.sh
arch-chroot /mnt chmod +x changepass.sh
arch-chroot /mnt ./changepass.sh
arch-chroot /mnt rm changepass.sh
fi
done
fi
}
# TODO: test UEFI install
install_bootloader(){
bootmenu="whiptail --menu --notags \"Select the bootloader you wish to use\" 10 50 3 \
\"syslinux\" \"Syslinux\" \
\"grub\" \"GRUB\" \
\"uefi\" \"bootctl(UEFI)\"
"
bootchoice=$(eval $bootmenu 3>&1 1>&2 2>&3)
if [[ $bootchoice != "" ]]; then
if [[ $bootchoice == "syslinux" ]]; then
arch-chroot /mnt pacman -S syslinux
arch-chroot /mnt syslinux-install_update -i -a -m
whiptail --msgbox "Please confirm that the syslinux installation chose the correct root partition"
vim /mnt/boot/syslinux/syslinux.cfg
elif [[ $bootchoice == "grub" ]]; then
arch-chroot /mnt pacman -S grub
for disk in $(ls /dev | grep -e "^sd.$" | xargs); do
diskmenu="$diskmenu \"/dev/$disk\" \"\""
done
diskmenu="whiptail --menu --noitem \"Please select the disk on which you want to install GRUB\" 15 50 5"
disk=$(eval $diskmenu 3>&1 1>&2 2>&3)
if [[ $disk != "" ]]; then
arch-chroot /mnt grub-install --target=i386-pc --recheck --debug $disk
arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg
fi
elif [[ $bootchoice == "uefi" ]]; then
arch-chroot /mnt bootctl install
echo "title Arch Linux" >> /mnt/boot/loader/entries/arch.conf
echo "linux /vmlinuz-linux" >> /mnt/boot/loader/entries/arch.conf
echo "initrd /initramfs-linux.img" >> /mnt/boot/loader/entries/arch.conf
echo "options root=/dev/sda2 rw" >> /mnt/boot/loader/entries/arch.conf
# this may not be correct
echo "timeout 3" >> /mnt/boot/loader/loader.conf
echo "default arch" >> /mnt/boot/loader/loader.conf
fi
fi
}
install_drivers(){
drivermenu="whiptail --menu --notags \"Select your video driver\" 15 50 7 \
\"xf86-video-ati\" \"ati\" \
\"xf86-video-intel\" \"intel\" \
\"xf86-video-nouveau\" \"nouveau\" \
\"nvidia\" \"nvidia\" \
\"nvidia-340xx\" \"nvidia-340xx\" \
\"nvidia-304xx\" \"nvidia-304xx\" \
\"virtualbox-guest-utils\" \"virtualbox\" \
"
driver=$(eval $drivermenu 3>&1 1>&2 2>&3)
if [[ $driver != "" ]]; then
arch-chroot /mnt pacman -S $driver
fi
}
install_desktop(){
demenu="whiptail --menu --notags \"Select the DE you wish to install\" 17 50 9 \
\"cinnamon\" \"Cinnamon\" \
\"enlightenment\" \"Enlightenment\" \
\"gnome\" \"Gnome\" \
\"kdebase-workspace\" \"KDE 4\" \
\"plasma\" \"KDE 5 Plasma\" \
\"lxde\" \"LXDE\" \
\"lxqt\" \"LXQt\" \
\"mate\" \"MATE\" \
\"xfce4\" \"Xfce\" \
"
wmmenu="whiptail --menu --notags \"Select the WM you wish to install\" 21 50 13 \
\"blackbox\" \"Blackbox\" \
\"fluxbox\" \"Fluxbox\" \
\"openbox\" \"Openbox\"
\"fvwm\" \"FVWM\" \
\"icewm\" \"iceWM\" \
\"jwm\" \"JWM\" \
\"windowmaker\" \"Window Maker\" \
\"bspwm\" \"Bspwm\" \
\"herbstluftwm\" \"Herbstluftwm\" \
\"awesome\" \"Awesome\" \
\"dwm\" \"dwm\" \
\"i3\" \"i3\" \
\"xmonad\" \"xmonad\" \
"
DEorWM=$(whiptail --menu --notags "Would you like to install a DE or a WM?" 10 43 2 "de" "Desktop Environment" "wm" "Window Manager" 3>&1 1>&2 2>&3)
if [[ $DEorWM != "" ]]; then
if [[ $DEorWM == "de" ]]; then
menuchoice=$(eval $demenu 3>&1 1>&2 2>&3)
elif [[ $DEorWM == "wm" ]]; then
menuchoice=$(eval $wmmenu 3>&1 1>&2 2>&3)
fi
fi
if [[ $menuchoice != "" ]]; then
arch-chroot /mnt pacman -S xorg-server xorg-server-utils xorg-xinit xorg-twm xorg-xclock xterm
arch-chroot /mnt pacman -S $menuchoice
fi
}
install_helper(){
whiptail --msgbox "Note: Installation of an AUR helper requires installation of the base-devel package" 15 50
helpermenu="whiptail --menu --notags \"Select a AUR helper to install\" 15 50 5 \
\"aura\" \"Aura\" \
\"autoaur\" \"Autoaur\" \
\"cower\" \"Cower\" \
\"packer\" \"Packer\" \
\"yaourt\" \"Yaourt\" \
"
helper=$(eval $helpermenu 3>&1 1>&2 2>&3)
if [[ $helper != "" ]]; then
mkdir /mnt/home/build
cp helper-install.sh /mnt/home/build
arch-chroot /mnt /home/build/helper-install.sh $helper
fi
}
get_partitions(){
# Obtain list of disk partitions
parts=$(fdisk -l | grep -e "^/dev/" | awk '{print $1}');
}
# Create string of command for main menu
mainmenu="whiptail --menu --notags \"Arch Install Scripts\" 25 50 16 \
\"part\" \"Partition Disk(s)\" \
\"format\" \"Format Partitions\" \
\"swap\" \"Setup Swap\" \
\"mount\" \"Mount Paritions\" \
\"base\" \"Install Base System\" \
\"hostname\" \"Set Hostname\" \
\"network\" \"Networking Tools\"
\"time\" \"Set Timezone\" \
\"locale\" \"Set Locale\" \
\"root\" \"Set Root Password\" \
\"users\" \"Add User(s)\" \
\"boot\" \"Install Bootloader\" \
\"drivers\" \"Install Graphics Drivers\" \
\"desktop\" \"Install Desktop Environment\" \
\"helper\" \"Install AUR Helper\"
\"done\" \"Make Initial RAM Image and Exit Script\" \
"
mainmenuchoice="default"
while [[ $mainmenuchoice != "done" && $mainmenuchoice != "" ]]; do
mainmenuchoice=$(eval $mainmenu 3>&1 1>&2 2>&3)
case $mainmenuchoice in
"part")
cfdisk;;
"format")
format_disks;;
"swap")
setup_swap;;
"mount")
mount_partitions;;
"base")
pacstrap /mnt base sudo
genfstab -p /mnt >> /mnt/etc/fstab;;
"hostname")
set_hostname;;
"network")
setup_network;;
"time")
set_timezone;;
"locale")
set_locale;;
"root")
set_root_passwd;;
"users")
add_user;;
"boot")
install_bootloader;;
"drivers")
install_drivers;;
"desktop")
install_desktop;;
"helper")
install_helper;;
"done")
arch-chroot /mnt mkinitcpio -p linux;;
esac
done