-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_pacstrap.sh
executable file
·329 lines (271 loc) · 10.5 KB
/
1_pacstrap.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
#!/bin/bash
# FILES
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
CONFIG_FILE=$SCRIPT_DIR/setup.conf
# Source Helper
source "$SCRIPT_DIR/helper.sh"
# SYNCHRONIZE
echo ""
echo -e "-------------------------------------------------------------------------"
echo -e "-----------Setting up mirrors for faster downloads-----------------------"
echo -e "-------------------------------------------------------------------------"
echo ""
_distroType=$(sed '$!d' "$CONFIG_FILE")
if [[ "$_distroType" = "artix" ]]; then
sed -i 's/#Color/Color\nILoveCandy/' /etc/pacman.conf
sed -i 's/#ParallelDownloads = 5/ParallelDownloads = 16/' /etc/pacman.conf
sudo pacman -Syy
install "artix-archlinux-support" "pac"
sudo tee -a /etc/pacman.conf <<EOF
[extra]
Include = /etc/pacman.d/mirrorlist-arch
[community]
Include = /etc/pacman.d/mirrorlist-arch
EOF
sudo pacman-key --populate archlinux
sudo pacman -Syy
install "reflector" "pac"
reflector --verbose -c DE --latest 5 --fastest 5 --protocol https --sort rate --save /etc/pacman.d/mirrorlist-arch
sudo pacman -Syy
else
timedatectl set-ntp true
sed -i 's/#Color/Color\nILoveCandy/' /etc/pacman.conf
sed -i 's/#ParallelDownloads = 5/ParallelDownloads = 16/' /etc/pacman.conf
reflector --verbose -c DE --latest 5 --fastest 5 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
install "archlinux-keyring" "pac"
pacman -Syyy
fi
# PARTITIONING
echo ""
echo "--------------------------------------------------"
echo "-------Auto partitioning the disk...--------------"
echo "--------------------------------------------------"
echo ""
# Encryption status
encryptStatus=$(sed -n '11p' <"$CONFIG_FILE")
# Disk to operate
DISK=$(sed -n '5p' <"$CONFIG_FILE")
# Delete old partition layout and re-read partition table
wipefs -af "${DISK}"
sgdisk --zap-all --clear "${DISK}"
partprobe "${DISK}"
# Partition disk and re-read partition table
if [[ "$encryptStatus" = "encrypt" ]]; then
sgdisk -n 1:0:+1G -t 1:ef00 -c 1:EFI "${DISK}"
sgdisk -n 2:0:0 -t 2:8309 -c 2:"Arch Linux" "${DISK}"
else
sgdisk -n 1:0:+1G -t 1:ef00 -c 1:EFI "${DISK}"
sgdisk -n 2:0:0 -t 2:8300 -c 2:"Arch Linux" "${DISK}"
fi
partprobe "${DISK}"
if [[ "$encryptStatus" = "encrypt" ]]; then
# LUKS Setup
echo ""
echo "-----------------------------------------------------"
echo "--------------LUKS Setup...--------------------------"
echo "-----------------------------------------------------"
echo ""
# Encrypt and open LUKS partition
LUKS_PASSWORD=$(sed -n '12p' <"$CONFIG_FILE")
# ADD FLAGS FOR SSD PERFORMANCE
driveType=$(sed -n '4p' <"$CONFIG_FILE")
if [[ "$driveType" = "ssd" ]]; then
if [[ ${DISK} =~ "nvme" ]]; then
echo "${LUKS_PASSWORD}" | cryptsetup luksFormat --perf-no_read_workqueue --perf-no_write_workqueue --type luks1 -c aes-xts-plain64 -s 256 --use-random "${DISK}p2"
echo "${LUKS_PASSWORD}" | cryptsetup luksOpen --allow-discards --perf-no_read_workqueue --perf-no_write_workqueue "${DISK}p2" cryptroot
else
echo "${LUKS_PASSWORD}" | cryptsetup luksFormat --perf-no_read_workqueue --perf-no_write_workqueue --type luks1 -c aes-xts-plain64 -s 256 --use-random "${DISK}2"
echo "${LUKS_PASSWORD}" | cryptsetup luksOpen --allow-discards --perf-no_read_workqueue --perf-no_write_workqueue "${DISK}2" cryptroot
fi
else
echo "${LUKS_PASSWORD}" | cryptsetup luksFormat --type luks1 -c aes-xts-plain64 -s 256 --use-random "${DISK}2"
echo "${LUKS_PASSWORD}" | cryptsetup luksOpen "${DISK}2" cryptroot
fi
# FORMAT
echo ""
echo "-----------------------------------------------------"
echo "--------------Formatting disk...---------------------"
echo "-----------------------------------------------------"
echo ""
FS=$(sed -n '1p' <"$CONFIG_FILE")
if [[ "$FS" = "btrfs" ]]; then
if [[ ${DISK} =~ "nvme" ]]; then
mkfs.fat -F32 "${DISK}p1"
mkfs.btrfs -f /dev/mapper/cryptroot
else
mkfs.fat -F32 "${DISK}1"
mkfs.btrfs -f /dev/mapper/cryptroot
fi
elif [[ "$FS" = "ext4" ]]; then
if [[ ${DISK} =~ "nvme" ]]; then
mkfs.fat -F32 "${DISK}p1"
mkfs.ext4 -f /dev/mapper/cryptroot
else
mkfs.fat -F32 "${DISK}1"
mkfs.ext4 -f /dev/mapper/cryptroot
fi
fi
# MOUNT
echo ""
echo "-----------------------------------------------------"
echo "--------------Mounting disk...-----------------------"
echo "-----------------------------------------------------"
echo ""
if [[ "$FS" = "btrfs" ]]; then
if [[ ${DISK} =~ "nvme" ]]; then
mount /dev/mapper/cryptroot /mnt
btrfs su cr /mnt/@
btrfs su cr /mnt/@home
btrfs su cr /mnt/@snapshots
btrfs su cr /mnt/@var_log
umount /mnt
mount -o noatime,compress-force=zstd,commit=120,space_cache=v2,ssd,discard=async,subvol=@ /dev/mapper/cryptroot /mnt
mkdir -p /mnt/{home,.snapshots,var_log}
mount -o noatime,compress-force=zstd,commit=120,space_cache=v2,ssd,discard=async,subvol=@home /dev/mapper/cryptroot /mnt/home
mount -o noatime,compress-force=zstd,commit=120,space_cache=v2,ssd,discard=async,subvol=@snapshots /dev/mapper/cryptroot /mnt/.snapshots
mount -o noatime,compress-force=zstd,commit=120,space_cache=v2,ssd,discard=async,subvol=@var_log /dev/mapper/cryptroot /mnt/var_log
mkdir -p /mnt/boot/efi
mount "${DISK}p1" /mnt/boot/efi
else
mount /dev/mapper/cryptroot /mnt
btrfs su cr /mnt/@
btrfs su cr /mnt/@home
btrfs su cr /mnt/@snapshots
btrfs su cr /mnt/@var_log
umount /mnt
mount -o noatime,compress-force=zstd,commit=120,space_cache=v2,ssd,discard=async,subvol=@ /dev/mapper/cryptroot /mnt
mkdir -p /mnt/{home,.snapshots,var_log}
mount -o noatime,compress-force=zstd,commit=120,space_cache=v2,ssd,discard=async,subvol=@home /dev/mapper/cryptroot /mnt/home
mount -o noatime,compress-force=zstd,commit=120,space_cache=v2,ssd,discard=async,subvol=@snapshots /dev/mapper/cryptroot /mnt/.snapshots
mount -o noatime,compress-force=zstd,commit=120,space_cache=v2,ssd,discard=async,subvol=@var_log /dev/mapper/cryptroot /mnt/var_log
mkdir -p /mnt/boot/efi
mount "${DISK}1" /mnt/boot/efi
fi
elif [[ "$FS" = "ext4" ]]; then
if [[ ${DISK} =~ "nvme" ]]; then
mount -t ext4 /dev/mapper/cryptroot /mnt
umount /mnt
mkdir -p /mnt/boot/efi
mount "${DISK}p1" /mnt/boot/efi
else
mount -t ext4 /dev/mapper/cryptroot /mnt
umount /mnt
mkdir -p /mnt/boot/efi
mount "${DISK}1" /mnt/boot/efi
fi
fi
elif [[ "$encryptStatus" = "noencrypt" ]]; then
# FORMAT
echo ""
echo "-----------------------------------------------------"
echo "--------------Formatting disk...---------------------"
echo "-----------------------------------------------------"
echo ""
FS=$(sed -n '1p' <"$CONFIG_FILE")
if [[ "$FS" = "btrfs" ]]; then
if [[ ${DISK} =~ "nvme" ]]; then
mkfs.fat -F32 "${DISK}p1"
mkfs.btrfs -f "${DISK}p2"
else
mkfs.fat -F32 "${DISK}1"
mkfs.btrfs -f "${DISK}2"
fi
elif [[ "$FS" = "ext4" ]]; then
if [[ ${DISK} =~ "nvme" ]]; then
mkfs.fat -F32 "${DISK}p1"
mkfs.ext4 -f "${DISK}p2"
else
mkfs.fat -F32 "${DISK}1"
mkfs.ext4 -f "${DISK}2"
fi
fi
# MOUNT
echo ""
echo "-----------------------------------------------------"
echo "--------------Mounting disk...-----------------------"
echo "-----------------------------------------------------"
echo ""
if [[ "$FS" = "btrfs" ]]; then
if [[ ${DISK} =~ "nvme" ]]; then
mount "${DISK}p2" /mnt
btrfs su cr /mnt/@
btrfs su cr /mnt/@home
btrfs su cr /mnt/@snapshots
btrfs su cr /mnt/@var_log
umount /mnt
mount -o noatime,compress-force=zstd,commit=120,space_cache=v2,ssd,discard=async,subvol=@ "${DISK}p2" /mnt
mkdir -p /mnt/{home,.snapshots,var_log}
mount -o noatime,compress-force=zstd,commit=120,space_cache=v2,ssd,discard=async,subvol=@home "${DISK}p2" /mnt/home
mount -o noatime,compress-force=zstd,commit=120,space_cache=v2,ssd,discard=async,subvol=@snapshots "${DISK}p2" /mnt/.snapshots
mount -o noatime,compress-force=zstd,commit=120,space_cache=v2,ssd,discard=async,subvol=@var_log "${DISK}p2" /mnt/var_log
mkdir -p /mnt/boot/efi
mount "${DISK}p1" /mnt/boot/efi
else
mount "${DISK}2" /mnt
btrfs su cr /mnt/@
btrfs su cr /mnt/@home
btrfs su cr /mnt/@snapshots
btrfs su cr /mnt/@var_log
umount /mnt
mount -o noatime,compress-force=zstd,commit=120,space_cache=v2,ssd,discard=async,subvol=@ "${DISK}2" /mnt
mkdir -p /mnt/{home,.snapshots,var_log}
mount -o noatime,compress-force=zstd,commit=120,space_cache=v2,ssd,discard=async,subvol=@home "${DISK}2" /mnt/home
mount -o noatime,compress-force=zstd,commit=120,space_cache=v2,ssd,discard=async,subvol=@snapshots "${DISK}2" /mnt/.snapshots
mount -o noatime,compress-force=zstd,commit=120,space_cache=v2,ssd,discard=async,subvol=@var_log "${DISK}2" /mnt/var_log
mkdir -p /mnt/boot/efi
mount "${DISK}1" /mnt/boot/efi
fi
elif [[ "$FS" = "ext4" ]]; then
if [[ ${DISK} =~ "nvme" ]]; then
mount -t ext4 "${DISK}p2" /mnt
umount /mnt
mkdir -p /mnt/boot/efi
mount "${DISK}p1" /mnt/boot/efi
else
mount -t ext4 "${DISK}2" /mnt
umount /mnt
mkdir -p /mnt/boot/efi
mount "${DISK}1" /mnt/boot/efi
fi
fi
fi
# INSTALL BASE SYSTEM
if [[ "$_distroType" = "artix" ]]; then
strapType="Base"
else
strapType="Pac"
fi
echo ""
echo "----------------------------------------------------"
echo "--------------${strapType}strapping...--------------"
echo "----------------------------------------------------"
echo ""
## Auto Detect Intel or AMD CPU
proc_type=$(lscpu | awk '/Vendor ID:/ {print $3}')
if [[ ${proc_type} =~ "GenuineIntel" ]]; then
echo ""
echo -e "\e[34mInstalling Intel microcode ...\e[0m"
echo ""
if [[ "$_distroType" = "artix" ]]; then
for i in {1..5}; do basestrap /mnt base base-devel linux-zen linux-zen-headers linux-firmware intel-ucode btrfs-progs git vim openrc elogind-openrc && break || sleep 1; done
else
for i in {1..5}; do pacstrap /mnt base base-devel linux-zen linux-zen-headers linux-firmware intel-ucode btrfs-progs git vim && break || sleep 1; done
fi
elif [[ ${proc_type} =~ "AuthenticAMD" ]]; then
echo ""
echo -e "\e[31mInstalling AMD microcode ...\e[0m"
echo ""
if [[ "$_distroType" = "artix" ]]; then
for i in {1..5}; do basestrap /mnt base base-devel linux-zen linux-zen-headers linux-firmware amd-ucode btrfs-progs git vim openrc elogind-openrc && break || sleep 1; done
else
for i in {1..5}; do pacstrap /mnt base base-devel linux-zen linux-zen-headers linux-firmware amd-ucode btrfs-progs git vim && break || sleep 1; done
fi
fi
# GENERATE UUID OF THE DISKS
if [[ "$_distroType" = "artix" ]]; then
fstabgen -U /mnt >>/mnt/etc/fstab
else
genfstab -U /mnt >>/mnt/etc/fstab
fi
# COPY SCRIPTS TO THE MOUNT DIRECTORY
cp -r "$SCRIPT_DIR" /mnt/