This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
archix.sh
executable file
·455 lines (387 loc) · 15.5 KB
/
archix.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
#!/bin/bash
if [ "ARCHIX_DISABLE_COLORS" == "1" ]; then
RED=""
GREEN=""
YELLOW=""
BLUE=""
NC-""
else
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[1;34m'
YELLOW='\033[1;33m'
NC='\033[0m'
fi
if [ "ARCHIX_RICH_SYMBOLS" == "1" ]; then
CHECKMARK='[\xE2\x9C\x94]'
CROSS='[\xE2\x9C\x98]'
BULLET='[‣]'
else
CHECKMARK='[√]'
CROSS='[X]'
BULLET='[>]'
fi
QUESTION='[?]'
WARNING='[!]'
error() {
echo -e "$RED $CROSS $1$NC"
exit 1
}
cd "$(dirname "$0")" || echo -e "Could not change directory to the script directory. Please download the script to a stable directory and try again."
echo -e "Welcome to Archix, a simple bash script to install a new Arch Linux system."
echo -e "Make sure to run this script as root in the ArchISO."
echo -e
echo -e "$GREEN $BULLET Checking for root access...$NC"
if [ "$EUID" -ne 0 ]; then
error "You're not root. Please run this script as root."
exit 1
else
echo -e "$GREEN $CHECKMARK You are root!$NC"
fi
echo -e "$BLUE $QUESTION What is your preferred editor?"
echo -e " $BULLET 1. nano"
echo -e " $BULLET 2. vim"
echo -e "$NC"
read -r -p " Please enter your choice: " editor
if [ "$editor" == "1" ]; then
export EDITOR=nano
elif [ "$editor" == "2" ]; then
export EDITOR=vim
else
echo -e "$RED $CROSS Invalid choice!$NC"
exit 1
fi
echo -e "$BLUE $QUESTION What is your computer's firmware?"
echo -e " $BULLET 1. BIOS"
echo -e " $BULLET 2. UEFI"
echo -e "$NC"
read -p " Please enter your choice: " firmware
if [ "$firmware" == "2" ]; then
echo -e "$BLUE $BULLET Checking UEFI boot mode...$NC"
if [ "$(cat /sys/firmware/efi/fw_platform_size)" == "0" ]; then
echo -e "$RED $CROSS UEFI boot mode is not enabled."
echo -e " Please boot in UEFI mode and try again."
echo -e "$NC"
exit 1
fi
echo -e "$GREEN $CHECKMARK UEFI boot mode is enabled.$NC"
fi
echo -e "$BLUE $BULLET Checking for internet connection...$NC"
if ping -q -c 1 -W 1 archlinux.org >/dev/null; then
echo -e "$GREEN $CHECKMARK Internet connection is available.$NC"
else
echo -e "$RED $CROSS Internet connection is not available."
echo -e " Please connect to the internet and try again."
echo -e "$NC"
exit 1
fi
echo -e "$BLUE $BULLET Refreshing repositories...$NC"
pacman -Syy || error "An error occurred while refreshing repositories."
echo -e "$BLUE $BULLET Enabling Pacman parallel downloads...$NC"
sed -i '37s/^#ParallelDownloads/ParallelDownloads/' /etc/pacman.conf
echo -e "$BLUE $BULLET Enabling NTP clock synchronization...$NC"
timedatectl set-ntp true || error "An error occurred while enabling NTP clock synchronization."
sleep 2
echo -e "$GREEN $CHECKMARK Enabled NTP clock synchronization.$NC"
echo -e "$BLUE $QUESTION Have you already partitioned your hard drive?"
echo -e " $BULLET 1. Yes"
echo -e " $BULLET 2. No"
echo -e "$NC"
read -p "Please enter your choice: " partitioned
if [ "$partitioned" == "2" ]; then
# echo -e "$BLUE $QUESTION Do you want to partition your hard drive manually?"
# echo -e " $BULLET 1. Yes"
# echo -e " $BULLET 2. No (BIOS not yet supported, UEFI currently broken, home partitions are not supported)"
# echo -e "$NC"
# read -p "Please enter your choice: " manpartition
manpartition="1"
if [ "$manpartition" == "1" ]; then
echo -e "$YELLOW $BULLET $WARNING Only EXT4 partitions are supported.$NC"
echo
echo -e "$BLUE $BULLET Here is the list of devices you can use:$NC"
lsblk -d -p -o NAME,SIZE
read -p "Please enter the device name (e.g. /dev/sda): " device
if [ -z "$device" ]; then
echo -e "$RED $CROSS Device name is empty.$NC"
exit 1
fi
if [ ! -b "$device" ]; then
echo -e "$RED $CROSS Device name is not valid.$NC"
exit 1
fi
if [ "$firmware" == "2" ]; then
cgdisk $device || error "An error occurred while partitioning your hard drive."
else
echo -e "$YELLOW $BULLET $WARNING Please choose the DOS label.$NC"
sleep 2
cfdisk $device || error "An error occurred while partitioning your hard drive."
fi
echo -e "$BLUE $BULLET Here is the list of partitions you can use:$NC"
lsblk -p -o NAME,SIZE $device
read -p "Please enter the root partition (e.g. /dev/sda3): " rootdev
if [ -z "$rootdev" ]; then
error "$RED $CROSS Device name is empty.$NC"
fi
if [ ! -b "$rootdev" ]; then
error "$RED $CROSS Device name is not valid.$NC"
fi
if [ "$firmware" == "2" ]; then
read -p "Please enter the EFI System Partition (e.g. /dev/sda1): " efipart
if [ -z "$efipart" ]; then
error "$RED $CROSS EFI System Partition is empty.$NC"
fi
if [ ! -b "$efipart" ]; then
error "$RED $CROSS EFI System Partition is not valid.$NC"
fi
else
efipart=""
fi
read -p "Please enter the swap partition (e.g. /dev/sda2): " swapdev
if [ -z "$swapdev" ]; then
echo -e "$YELLOW $WARNING Swap partition is empty. Not using one. $NC"
else
if [ ! -b "$swapdev" ]; then
error "$RED $CROSS Swap partition is not valid.$NC"
fi
fi
read -p "Please enter the home partition (e.g. /dev/sda4): " homedev
if [ -z "$homedev" ]; then
echo -e "$YELLOW $WARNING Home partition is empty. Not using one. $NC"
else
if [ ! -b "$homedev" ]; then
error "$RED $CROSS Home partition is not valid.$NC"
fi
fi
else
# TODO: Auto partitioning for BIOS
if [ "$firmware" == "1" ]; then
error "Automated partitioning for BIOS is not yet supported."
fi
echo -e "$BLUE $BULLET Here is the list of devices you can use:$NC"
lsblk -d -p -o NAME,SIZE
read -p "Please enter the device name (e.g. /dev/sda): " device
if [ -z "$device" ]; then
echo -e "$RED $CROSS Device name is empty.$NC"
exit 1
fi
if [ ! -b "$device" ]; then
echo -e "$RED $CROSS Device name is not valid.$NC"
exit 1
fi
echo
echo -e "$YELLOW $BULLET $WARNING Home partitions are not yet supported.$NC"
echo -e "$YELLOW $BULLET If you want to create a home partition, please choose manual partitioning.$NC"
echo -e "$YELLOW $BULLET $WARNING Only EXT4 partitions are supported.$NC"
echo -e "$BLUE $BULLET The following partitions will be created:"
if [ "$firmware" == "2" ]; then
echo -e " $BULLET 1. /boot (FAT32; EFI System Partition; 500 MB)"
echo -e " $BULLET 2. swap (SWAP; SWAP; 2 GB)"
echo -e " $BULLET 3. / (EXT4; Linux Filesystem; 100% of remaining space)"
else
echo -e " $BULLET 1. swap (SWAP; SWAP; 2 GB)"
echo -e " $BULLET 2. / (EXT4; Linux Filesystem; 100% of remaining space)"
fi
echo -e "$NC"
echo -e "$BLUE $QUESTION Do you want to continue?"
echo -e " $BULLET 1. Yes"
echo -e " $BULLET 2. No"
echo -e "$NC"
read -p "Please enter your choice: " cont
if [ "$cont" == "2" ]; then
echo -e "$RED $CROSS Aborting!$NC"
exit 1
fi
echo -e "$BLUE $BULLET Partitioning your hard drive...$NC"
echo -e "$BLUE $BULLET This may take a while...$NC"
# if [ "$firmware" == "2" ]; then
# TODO: fix this
# sgdisk -o \
# -n 1:0:+500M -t 2:EF00 \ # /boot
# -n 2:0:+2G -t 3:8200 \ # swap
# -n 3:0:0 -t 3:8300 \ # /
# $device || error "An error occurred while partitioning your hard drive."
# efipart = "$device1"
# swapdev = "$device2"
# rootdev = "$device3"
# else
# sfdisk -o \
# -n 1:0:+2G -t 3:8200 \ # swap
# -n 2:0:0 -t 3:8300 \ # /
# $device || error "An error occurred while partitioning your hard drive."
# efipart = ""
# swapdev = "$device1"
# rootdev = "$device2"
# fi
echo -e "$GREEN $CHECKMARK Partitioning completed.$NC"
fi
else
echo -e "$BLUE $BULLET Here is the list of devices you can use:$NC"
lsblk -d -p -o NAME,SIZE
read -p "Please enter the device name (e.g. /dev/sda): " device
if [ -z "$device" ]; then
echo -e "$RED $CROSS Device name is empty.$NC"
exit 1
fi
if [ ! -b "$device" ]; then
echo -e "$RED $CROSS Device name is not valid.$NC"
exit 1
fi
echo -e "$YELLOW $BULLET $WARNING Only EXT4 partitions are supported.$NC"
echo -e "$BLUE $BULLET Here is the list of partitions you can use:$NC"
lsblk -p -o NAME,SIZE $device
read -p "Please enter the root partition (e.g. /dev/sda2): " rootdev
if [ -z "$rootdev" ]; then
echo -e "$RED $CROSS Device name is empty.$NC"
exit 1
fi
if [ ! -b "$rootdev" ]; then
echo -e "$RED $CROSS Device name is not valid.$NC"
exit 1
fi
if [ "$firmware" == "2" ]; then
read -p "Please enter the EFI System Partition (e.g. /dev/sda1): " efipart
if [ -z "$efipart" ]; then
echo -e "$RED $CROSS EFI System Partition is empty.$NC"
exit 1
fi
if [ ! -b "$efipart" ]; then
echo -e "$RED $CROSS EFI System Partition is not valid.$NC"
exit 1
fi
fi
read -p "Please enter the swap partition (e.g. /dev/sda3): " swapdev
if [ -z "$swapdev" ]; then
echo -e "$YELLOW $WARNING Swap partition is empty. Not using one. $NC"
else
if [ ! -b "$swapdev" ]; then
echo -e "$RED $CROSS Swap partition is not valid.$NC"
exit 1
fi
fi
read -p "Please enter the home partition (e.g. /dev/sda4): " homedev
if [ -z "$homedev" ]; then
echo -e "$YELLOW $WARNING Home partition is empty. Not using one. $NC"
else
if [ ! -b "$homedev" ]; then
error "$RED $CROSS Home partition is not valid.$NC"
fi
fi
fi
echo -e "$BLUE $BULLET You entered the following information:"
echo -e " $BULLET 1. Device: $device"
echo -e " $BULLET 2. Root partition: $rootdev"
echo -e " $BULLET 3. Swap partition: $swapdev"
if [ "$firmware" == "2" ]; then
echo -e " $BULLET 4. EFI System Partition: $efipart"
fi
echo -e " $BULLET 5. Home partition: $homedev"
echo -e "$NC"
echo -e "$BLUE $QUESTION Is this correct?$NC"
echo -e " $BULLET 1. Yes"
echo -e " $BULLET 2. No"
echo -e "$NC"
read -p "Please enter your choice: " cont
if [ "$cont" == "2" ]; then
echo -e "$RED $CROSS Aborting!$NC"
exit 1
fi
echo -e "$BLUE $BULLET Creating the filesystems...$NC"
echo -e "$BLUE $BULLET This may take a while...$NC"
if [ "$firmware" == "2" ]; then
echo -e "$BLUE $BULLET Formatting EFI System Partition as FAT32 (VFAT)...$NC"
mkfs.vfat $efipart || error "An error occurred while creating the EFI System Partition filesystem."
fi
echo -e "$BLUE $BULLET Formatting Root partition as EXT4...$NC"
mkfs.ext4 $rootdev || error "An error occurred while creating the Root partition filesystem."
if [ -n "$swapdev" ]; then
echo -e "$BLUE $BULLET Formatting Swap partition as SWAP...$NC"
mkswap $swapdev || error "An error occurred while creating the Swap partition filesystem."
fi
if [ -n "$homedev" ]; then
echo -e "$BLUE $BULLET Formatting Home partition as EXT4...$NC"
mkfs.ext4 $homedev || error "An error occurred while creating the Home partition filesystem."
fi
echo -e "$GREEN $CHECKMARK Filesystems created.$NC"
echo -e "$BLUE $BULLET Mounting the filesystems...$NC"
echo -e "$BLUE $BULLET Mounting Root partition...$NC"
mount $rootdev /mnt || error "An error occurred while mounting the Root partition."
echo -e "$GREEN $CHECKMARK Root partition mounted.$NC"
echo -e "$BLUE $BULLET Creating /boot mountpoint...$NC"
mkdir -p /mnt/boot
if [ "$firmware" == "2" ]; then
mkdir -p /mnt/boot/efi
echo -e "$BLUE $BULLET Mounting EFI System Partition...$NC"
mount $efipart /mnt/boot/efi || error "An error occurred while mounting the EFI System Partition."
echo -e "$GREEN $CHECKMARK EFI System Partition mounted.$NC"
fi
if [ -n "$swapdev" ]; then
echo -e "$BLUE $BULLET Mounting Swap partition...$NC"
swapon $swapdev || error "An error occurred while mounting the Swap partition."
echo -e "$GREEN $CHECKMARK Swap partition mounted.$NC"
fi
if [ -n "$homedev" ]; then
echo -e "$BLUE $BULLET Creating /home mountpoint...$NC"
mkdir -p /mnt/home
echo -e "$BLUE $BULLET Mounting Home partition...$NC"
mount $homedev /mnt/home || error "An error occurred while mounting the Home partition."
echo -e "$GREEN $CHECKMARK Home partition mounted.$NC"
fi
echo -e "$BLUE $QUESTION Which kernel do you want to install?$NC"
echo -e " $BULLET 1. Linux"
echo -e " $BULLET 2. Linux-LTS"
echo -e "$NC"
read -p "Please enter your choice: " kernel
if [ "$kernel" == "2" ]; then
kern="linux-lts"
else
kern="linux"
fi
echo -e "$BLUE $QUESTION What is your CPU manufacturer?$NC"
echo -e " $BULLET 1. AMD"
echo -e " $BULLET 2. Intel"
echo -e "$NC"
read -p " Please enter your choice: " cpu
if [ "$cpu" == "2" ]; then
ucode="intel-ucode"
else
ucode="amd-ucode"
fi
echo -e "$BLUE $BULLET Installing the base system...$NC"
echo -e "$BLUE $BULLET This may take a while...$NC"
pacstrap /mnt base base-devel linux-firmware $kern git vim nano $ucode || error "An error occurred while installing the base system."
echo -e "$GREEN $CHECKMARK Base system installed.$NC"
echo -e "$BLUE $BULLET Generating fstab...$NC"
genfstab -U /mnt >> /mnt/etc/fstab || error "An error occurred while generating fstab."
echo -e "$GREEN $CHECKMARK fstab generated.$NC"
echo -e "$BLUE $BULLET Copying the installation script...$NC"
cp -r $PWD/chroot.sh /mnt/install.sh || error "An error occurred while copying the installation script."
cp -r $PWD/user.sh /mnt/user.sh || error "An error occurred while copying the installation script."
echo -e "$GREEN $CHECKMARK Installation script copied.$NC"
echo -e "$BLUE $BULLET Chrooting into the new system...$NC"
echo "export EDTOR=$EDTOR" >> /mnt/envs
echo "export device=$device" >> /mnt/envs
echo "export firmware=$firmware" >> /mnt/envs
echo "export kern=$kern" >> /mnt/envs
echo "export ARCHIX_DISABLE_COLORS=$ARCHIX_DISABLE_COLORS" >> /mnt/envs
echo "export ARCHIX_RICH_SYMBOLS=$ARCHIX_RICH_SYMBOLS" >> /mnt/envs
arch-chroot /mnt /install.sh || error "An error occurred while chrooting into the new system."
echo -e "$GREEN $CHECKMARK Chroot exited.$NC"
echo -e "$BLUE $BULLET Deleting the installation script...$NC"
rm /mnt/install.sh || error "An error occurred while deleting the installation script."
rm /mnt/user.sh || error "An error occurred while deleting the installation script."
rm /mnt/envs || error "An error occurred while deleting the installation script."
echo -e "$GREEN $CHECKMARK Installation script deleted.$NC"
echo -e "$BLUE $BULLET Unmounting the filesystems...$NC"
umount -R /mnt || error "An error occurred while unmounting the filesystems."
echo -e "$GREEN $CHECKMARK Filesystems unmounted.$NC"
echo -e "$GREEN $CHECKMARK Installation finished.$NC"
echo -e "$GREEN $CHECKMARK Enjoy!$NC"
echo -en "$BLUE $BULLET Rebooting in "
for i in {5..1}; do
echo -en "$i "
sleep 1
done
echo -e "$NC"
echo -e "$BLUE $BULLET Rebooting...$NC"
reboot
echo -e "$RED $CROSS An error occurred while rebooting."