-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_install.sh
489 lines (412 loc) · 15.7 KB
/
start_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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
#!/bin/bash
#
# start_install.sh - part of the MiniArch project
# Copyright (C) 2024, JustScott, [email protected]
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#---------------- Defining Functions ----------------
{
ask_set_encryption() {
declare -g encrypt_system=""
local encrypt verify_encrypt
while :
do
read -p 'Use An Encrypted System? [y/N]: ' encrypt
read -p 'Are you sure? [y/N]: ' verify_encrypt
if [[ $encrypt == $verify_encrypt ]]; then
case $encrypt in
"y"|"Y"|"yes"|"YES")
encrypt_system=true
return 0
;;
""|"n"|"N"|"no"|"NO")
encrypt_system=false
return 0
;;
*)
echo -e "\n - Invalid response... possible responses are: y|Y|yes|YES|n|N|no|NO - \n"
continue
;;
esac
else
clear
echo -e "\n - Answers Don't Match - \n"
fi
done
}
ask_removable() {
declare -g removable_flag=""
local removable verify_removable
while :
do
read -p 'Will this system be removable (Installed on a USB drive, for example)? [y/N]: ' removable
read -p 'Are you sure? [y/N]: ' verify_removable
if [[ $removable == $verify_removable ]]; then
case $removable in
"y"|"Y"|"yes"|"YES")
removable_flag="--removable"
return 0
;;
""|"n"|"N"|"no"|"NO")
return 0
;;
*)
echo -e "\n - Invalid response... possible responses are: y|Y|yes|YES|n|N|no|NO - \n"
continue
;;
esac
else
clear
echo -e "\n - Answers Don't Match - \n"
fi
done
}
get_filesystem_type() {
declare -g filesystem=""
local OPTION
echo -e "\n\e[1mChoose a filesystem type (if you're not sure, choose ext4):\e[0m\n"
select OPTION in "ext4" "btrfs"; do
case $OPTION in
"ext4"|"btrfs")
filesystem="$OPTION"
break
;;
*)
echo "Not an option, try again..."
;;
esac
done
}
get_name() {
declare -g name=""
local name_verify
while :
do
read -p 'Enter Name: ' name
read -p 'Verify Name: ' name_verify
if [[ -z "$name" ]]
then
clear
echo -e " - Name Can't Be Empty - \n"
continue
fi
if [[ $name == $name_verify ]]
then
clear
echo -e " - Set as '$name' - \n"
sleep 2
break
else
clear
echo -e " - Names Don't Match - \n"
fi
done
}
get_user_password() {
declare -g user_password=""
local user_password_verify
echo -e "\n - Set Password for '$1' - "
while :
do
read -s -p 'Set Password: ' user_password
read -s -p $'\nverify Password: ' user_password_verify
if [[ $user_password == $user_password_verify ]]
then
clear
echo -e " - Set password for $1! - \n"
sleep 2
break
else
clear
echo -e " - Passwords Don't Match - \n"
fi
done
}
ask_kernel_preference() {
declare -g kernel=""
local OPTION kernel_options all_packages \
chosen_custom_kernel kernel_confirmation
kernel_options=()
all_packages="$(pacman -Slq)"
echo "$all_packages" | grep -x "linux" &>/dev/null && kernel_options+=("linux")
echo "$all_packages" | grep -x "linux-lts" &>/dev/null && kernel_options+=("linux-lts")
echo "${kernel_options[@]}" | grep "linux " | grep "linux-lts" &>/dev/null \
&& kernel_options+=("linux+linux-lts")
echo -e "\n\e[1mEnter an integer or a valid kernel name (can pass a custom kernel not show below):\e[0m\n"
select OPTION in ${kernel_options[@]} "choose custom"; do
case $OPTION in
"linux"|"linux-lts")
kernel="$OPTION"
break
;;
"linux+linux-lts")
kernel="linux linux-lts"
break
;;
"choose custom")
chosen_custom_kernel=$(echo "$all_packages" | fzf --reverse)
clear
[[ -z "$chosen_custom_kernel" ]] && continue
read -p $"Are you sure '$chosen_custom_kernel' is a kernel? [y/N]: " kernel_confirmation
case $kernel_confirmation in
"y"|"Y"|"yes"|"YES")
kernel="$chosen_custom_kernel"
break
;;
*)
continue
;;
esac
;;
*)
echo "Can only choose a number that correlates with one of the options..."
;;
esac
done
}
}
#----- Assign System, User, and Partition Information to Variables -----
if ! pacman -Syy >/dev/null 2>>$HOME/miniarcherrors.log; then
echo -e "\n - Pacmans having trouble synchronizing its repositories\n"
echo -e " + Wrote the error log to $HOME/miniarcherrors.log\n"
exit 1
fi
{
ACTION="Update the keyring & install necessary packages"
echo -n "...$ACTION..."
pacman -S --noconfirm fzf archlinux-keyring python arch-install-scripts \
>/dev/null 2>>$HOME/miniarcherrors.log \
&& echo "[SUCCESS]" \
|| { echo "[FAIL] wrote error log to $HOME/miniarcherrors.log"; exit; }
sleep 1
if [[ -d /sys/firmware/efi/efivars ]]; then
if modprobe efivars &>/dev/null || modprobe efivarfs &>/dev/null; then
export uefi_enabled=true || export uefi_enabled=false
fi
fi
echo "uefi_enabled=\"$uefi_enabled\"" >> activate_installation_variables.sh
sleep 2
clear
echo -e "* Prompt [1/10] *\n"
# Run python script, exit if the script returns an error code
python3 MiniArch/create_partition_table.py \
|| { echo -e "\n - Failed to create the partition table - \n"; exit; }
source activate_installation_variables.sh
if [[ -z "$root_partition" ]]; then
echo -e "\n - [ERROR] Failed to get the root partition, this shouldn't happen... stopping - \n"
exit 1
fi
clear
echo -e "* Prompt [2/10] *\n"
echo ' - Set System Name - '
get_name
if [[ -z "$name" ]]; then
echo -e "\n - [ERROR] Failed to get a system name, this shouldn't happen... stopping - \n"
exit 1
fi
echo -e "\nsystem_name=\"$name\"" >> activate_installation_variables.sh
clear
echo -e "* Prompt [3/10] *\n"
echo ' - Set User Name - '
get_name
if [[ -z "$name" ]]; then
echo -e "\n - [ERROR] Failed to get a user name, this shouldn't happen... stopping - \n"
exit 1
fi
echo -e "\nusername=\"$name\"" >> activate_installation_variables.sh
clear
echo -e "* Prompt [4/10] *\n"
get_user_password "$name"
echo -e "\nuser_password=\"$user_password\"" >> activate_installation_variables.sh
clear
echo -e "* Prompt [5/10] *\n"
echo -e "Choose your timezone (start typing to narrow down choices):"
user_timezone=$(timedatectl list-timezones | fzf --reverse --height=90%)
echo -e "\nuser_timezone=\"$user_timezone\"" >> activate_installation_variables.sh
clear
echo -e "* Prompt [6/10] *\n"
echo -e "Choose your locale (press <esc> to use 'en_US.UTF-8 UTF-8' (recommended) ):"
user_locale="$(cat /usr/share/i18n/SUPPORTED | fzf --reverse --height=90%)"
[[ -z "$user_locale" ]] && user_locale='en_US.UTF-8 UTF-8'
echo -e "\nuser_locale=\"$user_locale\"" >> activate_installation_variables.sh
clear
echo -e "* Prompt [7/10] *\n"
ask_kernel_preference
if [[ -z "$kernel" ]]; then
echo -e "\n - [ERROR] Failed to get a kernel, this shouldn't happen... stopping - \n"
exit 1
fi
clear
echo -e "* Prompt [8/10] *\n"
get_filesystem_type
if [[ -z "$filesystem" ]]; then
echo -e "\n - [ERROR] Failed to get a filesystem type, this shouldn't happen... stopping - \n"
exit 1
fi
echo -e "\nfilesystem=\"$filesystem\"" >> activate_installation_variables.sh
clear
echo -e "* Prompt [9/10] *\n"
ask_removable
echo -e "\nremovable_flag=\"$removable_flag\"" >> activate_installation_variables.sh
clear
echo -e "* Prompt [10/10] *\n"
ask_set_encryption
if [[ -z "$encrypt_system" ]]; then
echo -e "\n - [ERROR] Failed to get user's choice on encrypting the system, this shouldn't happen... stopping - \n"
exit 1
fi
echo -e "\nencrypt_system=$encrypt_system" >> activate_installation_variables.sh
}
#---------------- Create and Format Partitions ----------------
{
fs_device="$root_partition"
if [[ "$encrypt_system" == true ]]; then
# Prompt the user to enter encryption keys until they enter
# matching keys
clear
while :
do
cryptsetup luksFormat -s 512 -h sha512 $root_partition \
&& break \
|| { clear; echo -e "\n - Try Again - \n"; }
done
# Prompt the user for the encrypted partitions key until
# they enter the correct one
while :
do
if cryptsetup open $root_partition cryptdisk; then
break
else
clear
echo -e " - Wrong Key, Try Again - \n"
fi
done
fs_device="/dev/mapper/cryptdisk"
fi
clear
echo -e "\n - Starting Installation (no more user interaction needed) - \n"
ACTION="Use Filesystem: '$filesystem'"
case $filesystem in
"ext4")
{
echo 'y' | mkfs.ext4 $fs_device
mount $fs_device /mnt
}>/dev/null 2>>$HOME/miniarcherrors.log \
&& echo "[SUCCESS] $ACTION" \
|| { echo "[FAIL] $ACTION... wrote error log to $HOME/miniarcherrors.log"; exit; }
;;
"btrfs")
ACTION="Install btrfs-progs packages"
echo -n "...$ACTION..."
pacman -S --noconfirm btrfs-progs \
>/dev/null 2>>$HOME/miniarcherrors.log \
&& echo "[SUCCESS]" \
|| { echo "[FAIL] wrote error log to $HOME/miniarcherrors.log"; exit; }
{
echo 'y' | mkfs.btrfs -f $fs_device
mount $fs_device /mnt
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home
umount /mnt
# 256 is /mnt/@
mount $fs_device -o subvolid=256 /mnt
mkdir -p /mnt/home
# 257 is /mnt/@home
mount $fs_device -o subvolid=257 /mnt/home
}>/dev/null 2>>$HOME/miniarcherrors.log \
&& echo "[SUCCESS] $ACTION" \
|| { echo "[FAIL] $ACTION... wrote error log to $HOME/miniarcherrors.log"; exit; }
;;
*)
"echo [FAIL] $ACTION... no filesystem chosen"
exit
;;
esac
ACTION="Format boot partition"
# Only create a new boot partition if one doesn't already exist
if [[ $existing_boot_partition != True ]]
then
{
if [[ $uefi_enabled == true ]]
then
echo 'y' | mkfs.fat -F 32 $boot_partition >/dev/null 2>>$HOME/miniarcherrors.log \
&& echo "[SUCCESS] $ACTION" \
|| { echo "[FAIL] $ACTION... wrote error log to $HOME/miniarcherrors.log"; exit; }
else
echo 'y' | mkfs.ext4 $boot_partition >/dev/null 2>>$HOME/miniarcherrors.log \
&& echo "[SUCCESS] $ACTION" \
|| { echo "[FAIL] $ACTION... wrote error log to $HOME/miniarcherrors.log"; exit; }
fi
}
fi
mkdir -p /mnt/boot
mount $boot_partition /mnt/boot
}
#---------------- Prepare the root partition ------------------
{
if [[ $uefi_enabled == true ]]
then
ACTION="Install UEFI setup tools"
echo -n "...$ACTION..."
pacstrap /mnt efibootmgr dosfstools mtools >/dev/null 2>>$HOME/miniarcherrors.log \
&& echo "[SUCCESS]" \
|| { echo "[FAIL] wrote error log to $HOME/miniarcherrors.log"; exit; }
fi
sleep 1
if [[ $filesystem == "btrfs" ]]
then
ACTION="Install btrfs related packages"
echo -n "...$ACTION..."
pacstrap /mnt btrfs-progs snapper grub-btrfs >/dev/null 2>>$HOME/miniarcherrors.log \
&& echo "[SUCCESS]" \
|| { echo "[FAIL] wrote error log to $HOME/miniarcherrors.log"; exit; }
fi
sleep 1
ACTION="Install the kernel(s): '$kernel' (this may take a while)"
echo -n "...$ACTION..."
pacstrap /mnt base linux-firmware $kernel >/dev/null 2>>$HOME/miniarcherrors.log \
&& echo "[SUCCESS]" \
|| { echo "[FAIL] wrote error log to $HOME/miniarcherrors.log"; exit; }
sleep 1
ACTION="Install base operating system packages (this may take a while)"
echo -n "...$ACTION..."
pacstrap /mnt \
os-prober xdg-user-dirs-gtk grub networkmanager sudo htop \
base-devel git vim man-db man-pages >/dev/null 2>>$HOME/miniarcherrors.log \
&& echo "[SUCCESS]" \
|| { echo "[FAIL] wrote error log to $HOME/miniarcherrors.log"; exit; }
sleep 1
ACTION="Update fstab with new partition table"
genfstab -U /mnt >> /mnt/etc/fstab 2>>$HOME/miniarcherrors.log \
&& echo "[SUCCESS] $ACTION" \
|| { echo "[FAIL] $ACTION... wrote error log to $HOME/miniarcherrors.log"; exit; }
sleep 1
# Move necessary scripts to /mnt
cp MiniArch/finish_install.sh /mnt
mv activate_installation_variables.sh /mnt
# Create files to pass variables to fin
# Chroot into /mnt, and run the finish_install.sh script
arch-chroot /mnt /bin/bash finish_install.sh \
|| { echo -e "\n - 'arch-chroot /mnt bash finish_install.sh' failed - \n"; exit; }
clear
echo -e '\n - Installation Successful! - \n'
echo 'Unmounting partitions & Rebooting in 10 seconds...(hit CTRL+c to cancel)'
sleep 10
shred -uz /mnt/miniarcherrors.log
umount /mnt/boot
umount /mnt
[[ $encrypt_system == true ]] && cryptsetup luksClose cryptdisk
umount -a
reboot
}