-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbase.sh
130 lines (71 loc) · 2.04 KB
/
base.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
#!/bin/bash
enc_pass() {
echo "Drive Encryption password :"
read ENCRPYTION_PASS0
echo "Confirm Drive Encryption password :"
read ENCRPYTION_PASS1
[[ "$ENCRPYTION_PASS0" != "$ENCRPYTION_PASS1" ]] && enc_pass
}
enc_pass
single_disk () {
DISK="$(lsblk --list | grep 'disk' | awk '{print $1}')"
while true; do
read -p "$* >install on $DISK [y/n]: " yn
case $yn in
[Yy]*) disk_partition ;;
[Nn]*) multi_disk ;;
esac
done
}
manual_disk() {
lsblk && read -p "Drive Name (eg: sda or nvme) : " DISK
disk_partition
}
multi_disk() {
prompt="Please select the disk to install:"
options=( $(lsblk --list | grep 'disk' | awk '{ print $1}') )
PS3="$prompt "
select opt in "${options[@]}" "Enter manually" ; do
if (( REPLY == 1 + ${#options[@]} )) ; then
manual_disk
elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then
DISK="$opt"
echo "installing on $opt"; disk_partition
break
else
echo "Invalid option. Try again."
fi
done
disk_partition
}
disk_partition() {
wipefs -a -f /dev/$DISK
cat <<EOF | parted -a optimal /dev/$DISK
mklabel GPT
mkpart ESP fat32 0% 250M
mkpart primary ext4 250M 100%
EOF
mount_disk
}
mount_disk() {
DISK_EFI="$(lsblk --list -o +PARTLABEL /dev/$DISK | grep 'ESP' | awk '{ print $1 }')"
DISK_ROOT="$(lsblk --list -o +PARTLABEL /dev/$DISK | grep 'primary' | awk '{ print $1 }')"
echo -n "$ENCRPYTION_PASS1" | cryptsetup -y -v luksFormat /dev/$DISK_ROOT
echo -n "$ENCRPYTION_PASS1" | cryptsetup open /dev/$DISK_ROOT cryptroot
mkfs.ext4 /dev/mapper/cryptroot
mount /dev/mapper/cryptroot /mnt
mkfs.fat -F32 /dev/$DISK_EFI
mkdir /mnt/boot
mount /dev/$DISK_EFI /mnt/boot
base_pacstrap
}
base_pacstrap() {
pacstrap /mnt base sudo linux-lts linux-firmware vim git
genfstab -U /mnt >> /mnt/etc/fstab
cp base-chroot.sh /mnt/base-chroot.sh
chmod +x /mnt/base-chroot.sh
arch-chroot /mnt bash base-chroot.sh && rm /mnt/base-chroot.sh
umount -R /mnt
reboot
}
[[ $(lsblk | grep 'disk' | wc -l) ]] && single_disk "$@" || multi_disk "$@"