-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharchInstaller.sh
More file actions
478 lines (417 loc) · 14.2 KB
/
Copy patharchInstaller.sh
File metadata and controls
478 lines (417 loc) · 14.2 KB
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
#!/bin/bash
#Function to check encryption psswd
crypt_psswd_check() {
while true; do
read -s -p "Please insert partition pasword for encryption: " encryptPassword
echo
read -s -p "Confirm password again: " cryptConfirm
echo
if [ "$encryptPassword" == "$cryptConfirm" ]; then
break
else
echo "Passwords do not match. Please try again."
fi
done
}
#let's set fonts for HIDPI screens
setfont ter-132b
echo "#####################################################"
echo "# ARCH LINUX SCRIPT INSTALLER #"
echo "#####################################################"
echo " "
echo " "
####Questions for making the installation more faster for users that want to go outside and make a coffee in between.
read -r -p "Do you want to install any window manager ? write yes or no: " WMAnswer
echo
read -r -p "Do you want to install any Desktops ? write yes or no: " DesktopsAnswer
echo
if [[ "${DesktopsAnswer,,}" =~ ^(y|yes)$ ]]
then
read -r -p "Do you want to add many desktops ? write yes or no: " ManyDesktopsAnswer
echo
if [[ "${ManyDesktopsAnswer,,}" =~ ^(y|yes)$ ]]
then
read -r -p "Do you want to install all Desktops available in the script ? write yes or no: " AllDesktopsAnswer
echo
fi
if [[ "${ManyDesktopsAnswer,,}" =~ ^(n|no)$ ]]
then
read -r -p "Do you want to install just one desktop ? write yes or no: " OneDesktopAnswer
echo
fi
fi
#####This line of code is to see if is bios or uefi. Bios==32 & Uefi==64
BiosOrUefi=$(cat /sys/firmware/efi/fw_platform_size)
if [ "$BiosOrUefi" = '64' ]
then
echo "You are using a UEFI system"
echo
elif [ "$BiosOrUefi" = '32' ]
then
echo "You are using a UEFI system that can only use systemd-boot or grub"
echo
else
BiosOrUefi='0'
echo "You are using a BIOS system"
echo
fi
#Updates the system clock
timedatectl
#Making the partitions for the system
echo "Selecting drive for installation"
lsblk
echo "You will need to select a drive for your arch linux installation: for example, if you need sda drive put the path like this: /dev/sda"
echo "If you have more than one drive of the same type of kind and you see like /dev/sda1 and /dev/sda2, please add the number on which one you want to install Arch Linux on the prompt."
echo
read -r -p "Please insert your desire drive to make installation: " DISK
echo
read -r -p "Do you want to encrypt root partition? (yes/no) : " encryptFlag
echo
echo "Creating partitions on $DISK..."
### This if make the partitions for bios or uefi depending the case.
if [[ "${encryptFlag,,}" =~ ^(n|no)$ ]]
then
if [ "$BiosOrUefi" = '64' ]
then
# Create a GPT partition table (for UEFI systems)
sudo fdisk "$DISK" << EOF
g # Create a new empty partition table (GPT)
n # New partition for EFI System (512MB)
p
1
+512M
n # New partition for root (/) (remaining space)
p
2
w # Write changes and exit
EOF
elif [ "$BiosOrUefi" = '32' ]
then
sudo fdisk "$DISK" << EOF
g # Create a new empty partition table (GPT)
n # New partition for EFI System (512MB)
p
1
+512M
n # New partition for root (/) (remaining space)
p
2
w # Write changes and exit
EOF
elif [ "$BiosOrUefi" = '0' ]
then
sudo fdisk "$DISK" << EOF
o # Create new empy partition table (MBR)
n # New partition for EFI System (512MB)
p
1
+512M
n # New partition for root (/) (remaining space)
p
2
w # Write changes and exit
EOF
else
echo "something went wrong when creating partitions. Please cancel the script with ctrl + c"
sleep 3600
fi
elif [[ "${encryptFlag,,}" =~ ^(y|yes)$ ]]
then
if [ "$BiosOrUefi" = '64' ]
then
# Create a GPT partition table (for UEFI systems)
sudo fdisk "$DISK" << EOF
g # Create a new empty partition table (GPT)
n # New partition for EFI System (512MB)
p
1
+512M
n # New partition for root (/) (remaining space)
p
2
w # Write changes and exit
EOF
if [[ "$DISK" == /dev/nvme* ]]
then
crypt_psswd_check
cryptsetup luksFormat "$DISK"p2 << EOF
$encryptPassword
$encryptPassword
EOF
cryptsetup open "$DISK"p2 rootDrive << EOF
$encryptPassword
$encryptPassword
EOF
elif [[ "$DISK" == /dev/sd* ]]
then
crypt_psswd_check
cryptsetup luksFormat "$DISK"2 << EOF
$encryptPassword
$encryptPassword
EOF
cryptsetup open "$DISK"2 rootDrive << EOF
$encryptPassword
$encryptPassword
EOF
elif [[ "$DISK" == /dev/vd* ]]
then
crypt_psswd_check
cryptsetup luksFormat "$DISK"2 << EOF
$encryptPassword
$encryptPassword
EOF
cryptsetup open "$DISK"2 rootDrive << EOF
$encryptPassword
$encryptPassword
EOF
fi
elif [ "$BiosOrUefi" = '32' ]
then
# Create a GPT partition table (for UEFI systems)
sudo fdisk "$DISK" << EOF
g # Create a new empty partition table (GPT)
n # New partition for EFI System (512MB)
p
1
+512M
n # New partition for root (/) (remaining space)
p
2
w # Write changes and exit
EOF
if [[ "$DISK" == /dev/nvme* ]]
then
crypt_psswd_check
cryptsetup luksFormat "$DISK"p2 << EOF
$encryptPassword
$encryptPassword
EOF
cryptsetup open "$DISK"p2 rootDrive << EOF
$encryptPassword
$encryptPassword
EOF
elif [[ "$DISK" == /dev/sd* ]]
then
crypt_psswd_check
cryptsetup luksFormat "$DISK"2 << EOF
$encryptPassword
$encryptPassword
EOF
cryptsetup open "$DISK"2 rootDrive << EOF
$encryptPassword
$encryptPassword
EOF
elif [[ "$DISK" == /dev/vd* ]]
then
crypt_psswd_check
cryptsetup luksFormat "$DISK"2 << EOF
$encryptPassword
$encryptPassword
EOF
cryptsetup open "$DISK"2 rootDrive << EOF
$encryptPassword
$encryptPassword
EOF
fi
elif [ "$BiosOrUefi" = '0' ]
then
sudo fdisk "$DISK" << EOF
o # Create new empy partition table (MBR)
n # New partition for EFI System (512MB)
p
1
+512M
n # New partition for root (/) (remaining space)
p
2
w # Write changes and exit
EOF
if [[ "$DISK" == /dev/nvme* ]]
then
crypt_psswd_check
cryptsetup luksFormat "$DISK"p2 << EOF
$encryptPassword
$encryptPassword
EOF
cryptsetup open "$DISK"p2 rootDrive << EOF
$encryptPassword
$encryptPassword
EOF
elif [[ "$DISK" == /dev/sd* ]]
then
crypt_psswd_check
cryptsetup luksFormat "$DISK"2 << EOF
$encryptPassword
$encryptPassword
EOF
cryptsetup open "$DISK"2 rootDrive << EOF
$encryptPassword
$encryptPassword
EOF
elif [[ "$DISK" == /dev/vd* ]]
then
crypt_psswd_check
cryptsetup luksFormat "$DISK"2 << EOF
$encryptPassword
$encryptPassword
EOF
cryptsetup open "$DISK"2 rootDrive << EOF
$encryptPassword
$encryptPassword
EOF
fi
else
echo "something went wrong when creating partitions. Please cancel the script with ctrl + c"
sleep 3600
fi
fi
###Checks if drive is sata or mvme to create file systems and mounting.
if [[ "${encryptFlag,,}" =~ ^(n|no)$ ]]
then
if [[ "$DISK" == /dev/nvme* ]]
then
echo "Formatting partitions..."
sudo mkfs.fat -F 32 "${DISK}"p1 # EFI System Partition (ESP)
sudo mkfs.ext4 "${DISK}"p2 # Root partition
# Mount the partitions for installation
echo "Mounting partitions..."
mount "${DISK}"p2 /mnt
mkdir -p /mnt/boot
mount "${DISK}"p1 /mnt/boot
elif [[ "$DISK" == /dev/sd* ]]
then
echo "Formatting partitions..."
sudo mkfs.fat -F 32 "${DISK}"1 # EFI System Partition (ESP)
sudo mkfs.ext4 "${DISK}"2 # Root partition
# Mount the partitions for installation
echo "Mounting partitions..."
mount "${DISK}"2 /mnt
mkdir -p /mnt/boot
mount "${DISK}"1 /mnt/boot
elif [[ "$DISK" == /dev/vd* ]]
then
echo "Formatting partitions for virtual drive..."
sudo mkfs.fat -F 32 "${DISK}"1 # EFI System Partition (ESP)
sudo mkfs.ext4 "${DISK}"2 # Root partition
# Mount the partitions for installation
echo "Mounting partitions..."
mount "${DISK}"2 /mnt
mkdir -p /mnt/boot
mount "${DISK}"1 /mnt/boot
fi
elif [[ "${encryptFlag,,}" =~ ^(y|yes)$ ]]
then
if [[ "$DISK" == /dev/nvme* ]]
then
echo "Formatting partitions..."
sudo mkfs.fat -F 32 "${DISK}"p1 # EFI System Partition (ESP)
sudo mkfs.ext4 /dev/mapper/rootDrive # Root partition
# Mount the partitions for installation
echo "Mounting partitions..."
mount /dev/mapper/rootDrive /mnt
mkdir -p /mnt/boot
mount "${DISK}"p1 /mnt/boot
elif [[ "$DISK" == /dev/sd* ]]
then
echo "Formatting partitions..."
sudo mkfs.fat -F 32 "${DISK}"1 # EFI System Partition (ESP)
sudo mkfs.ext4 /dev/mapper/rootDrive # Root partition
# Mount the partitions for installation
echo "Mounting partitions..."
mount /dev/mapper/rootDrive /mnt
mkdir -p /mnt/boot
mount "${DISK}"1 /mnt/boot
elif [[ "$DISK" == /dev/vd* ]]
then
echo "Formatting partitions for virtual drive..."
sudo mkfs.fat -F 32 "${DISK}"1 # EFI System Partition (ESP)
sudo mkfs.ext4 /dev/mapper/rootDrive # Root partition
# Mount the partitions for installation
echo "Mounting partitions..."
mount /dev/mapper/rootDrive /mnt
mkdir -p /mnt/boot
mount "${DISK}"1 /mnt/boot
fi
fi
echo "Done. Proceeding with Arch Linux installation."
### Checks if cpu is intel, amd o virtualize
cpu_info=$(cat /proc/cpuinfo)
if echo "$cpu_info" | grep -iq 'intel'; then
cpu_vendor="Intel"
elif echo "$cpu_info" | grep -iq 'amd'; then
cpu_vendor="AMD"
else
cpu_vendor="virtualMachine"
fi
### INSTALL LIST AND ARCH CHROOT ###
sed -i 's/^#ParallelDownloads = 5/ParallelDownloads = 5/' /etc/pacman.conf
if [ "$cpu_vendor" = "Intel" ]
then
pacstrap -K /mnt base linux linux-firmware mkinitcpio intel-ucode efibootmgr git wget pipewire pipewire-docs pipewire-audio pipewire-alsa alsa-utils grub man-db man-pages texinfo vi vim eza networkmanager ntp bat alacritty kitty sudo fastfetch ufw lvm2
elif [ "$cpu_vendor" = "AMD" ]
then
pacstrap -K /mnt base linux linux-firmware mkinitcpio amd-ucode grub efibootmgr git wget pipewire pipewire-docs pipewire-audio pipewire-alsa alsa-utils man-db man-pages texinfo vi vim eza networkmanager ntp bat alacritty kitty sudo fastfetch ufw lvm2
elif [ "$cpu_vendor" = "virtualMachine" ]
then
pacstrap -K /mnt base linux linux-firmware mkinitcpio grub efibootmgr git wget pipewire pipewire-docs pipewire-audio pipewire-alsa alsa-utils man-db man-pages texinfo vi vim eza networkmanager ntp bat alacritty kitty sudo fastfetch ufw lvm2
fi
touch /mnt/etc/vconsole.conf #Dummy vconsole conf file
genfstab -U /mnt >> /mnt/etc/fstab
cp /root/ArchLinuxInstaller/chrootPart.sh /mnt/chrootPart.sh
arch-chroot /mnt /chrootPart.sh "$DISK" "$encryptFlag" "$WMAnswer" "$DesktopsAnswer" "$AllDesktopsAnswer" "$OneDesktopAnswer"
#Setting up lusk partition for booting up
partitionLuskID=$(blkid | grep "$DISK" | sort -hr | awk -F'"' '{ print $2 }' | head -n1)
partitionHardwareID=$(blkid | grep "$DISK" | sort -hr | awk -F'"' '{ print $2 }' | head -n1)
#sed -i "/^GRUB_CMDLINE_LINUX_DEFAULT=/ s/\(\".*\"\)/\1 cryptdevices=UUID=$partitionLuskID:cryptlvm root=UUID=$partitionHardwareID/" /mnt/etc/default/grub
#sed -i "/^GRUB_CMDLINE_LINUX_DEFAULT=/ s/\(\".*\"\)/\1 cryptdevices=UUID=$partitionLuskID:cryptlvm root=UUID=$partitionHardwareID/" /mnt/etc/default/grub
sed -i "/^GRUB_CMDLINE_LINUX_DEFAULT=/ s/\"$/ cryptdevice=UUID=$partitionHardwareID:rootDrive\"/" /mnt/etc/default/grub
#sed -i "/^HOOKS=/ s/\(([^)]*)\)/(\1 encrypt lvm2)/" /mnt/etc/mkinitcpio.conf Delete this in the future.
#sed -i "/^HOOKS=/ s/\([^)]*\)/\1 encrypt lvm2/" /mnt/etc/mkinitcpio.conf
#Making a busybox approach instead of systemd for mount encrypted root partition
if [[ "${encryptFlag,,}" =~ ^(y|yes)$ ]]
then
sed -i '/^HOOKS=/ s/\bsystemd\b//' /mnt/etc/mkinitcpio.conf
sed -i 's/\(base\)/\1 udev/' /mnt/etc/mkinitcpio.conf
sed -i '/^HOOKS=/ s/\bsd-vconsole\b/consolefont/' /mnt/etc/mkinitcpio.conf
sed -i 's/\(block\)/\1 encrypt lvm2/' /mnt/etc/mkinitcpio.conf
fi
cp /root/ArchLinuxInstaller/endingSetup.sh /mnt/endingSetup.sh
if [[ "${encryptFlag,,}" =~ ^(y|yes)$ ]]
then
arch-chroot /mnt /endingSetup.sh "$DISK" "$BiosOrUefi"
fi
umount -R /mnt
echo "#####################################################"
echo "# CONGRATULATIONS! #"
echo "#####################################################"
echo " "
echo " "
echo "You arch linux installation is completed, just write reboot to reboot the system and start using it!"
echo "by the way, you have alacritty and kitty by default terminals."
if [[ "${encryptFlag,,}" =~ ^(y|yes)$ ]]
then
mount /dev/mapper/rootDrive /mnt
mount /dev/vda1 /mnt/boot
echo " "
echo " "
echo "You encripted the root device, by default this script should make it work out of the box, but if that's not the case, the whole manual process is described in the last part of archInstaller.sh as comments."
echo "If you want to manually do a fix, over there you will find the documentation."
echo "But in practice this script should work out of the box, most if you only have one storage drive."
echo "For more than two devices, if you want you can check it if everything is in order, for that the partitions had been mounted already to check that."
echo "If you don't want to do that you can just umount the partitions and reboot, or just reboot."
echo "Enjoy your setup btw ^^"
fi
#### Information for encripted devices ####
#### If by some reason somethin is not working, the following is the whole manual process to make an encrypted drive boots:
#### "You have installed the encrypt root partition. But you don't have grub necesary files or healthy initramfs, you will need to do the following:
#### "To do that make this:"
#### "1) check if your drives are mounted with lsblk"
#### "2) blkid >> /etc/default/grub"
#### "3) Chroot with arch-chroot /mnt"
#### "4) Select the UUID of the for crypto_LUKS in the bottom of /etc/default/grub and decrypted drive UUID"
#### "5) In GRUB_CMDLINE_LINUX_DEFAULT add cryptdevice=UUID=<yourUUID>:cryptlvm root=UUID=<UUIDofDecryptedPartition>"
#### "6) In /etc/mkinitcpio.conf add in the HOOKS line: encrypt lvm2"
#### "7) run mkinitcpio -P "
#### "8) Install grub like grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB or for bios systems: grub-install ""$DISK"" "
#### "9) finally grub-mkconfig -o /boot/grub/grub.cfg"
#### "Then exit and reboot"