-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_sys.sh
157 lines (118 loc) · 3.66 KB
/
install_sys.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
#!/bin/bash
# Never run pacman -Sy on your system!
pacman -Sy dialog
timedatectl set-ntp true
dialog --defaultno --title "Are you sure?" --yesno \
"Hi, my name is Benjamin Shawki. \n\n\
This is the my personnal arch linux install. \n\n\
xoxo \n\n\
It will DESTROY EVERYTHING on one of your hard disk. \n\n\
Don't say YES if you are not sure what you're doing! \n\n\
Do you want to continue?" 15 60 || exit
dialog --no-cancel --inputbox "Enter a name for your computer." \
10 60 2> comp
# Verify boot (UEFI or BIOS)
uefi=0
ls /sys/firmware/efi/efivars 2> /dev/null && uefi=1
# Choosing the hard drive
devices_list=($(lsblk -d | awk '{print "/dev/" $1 " " $4 " on"}' \
| grep -E 'sd|hd|vd|nvme|mmcblk'))
dialog --title "Choose your hard drive" --no-cancel --radiolist \
"Where do you want to install your new system?\n\n\
Select with SPACE, valid with ENTER.\n\n\
WARNING: Everything will be DESTROYED on the hard disk!" \
15 60 4 "${devices_list[@]}" 2> hd
hd=$(cat hd) && rm hd
# Ask for the size of the swap partition
default_size="8"
dialog --no-cancel --inputbox \
"You need four partitions: Boot, Root and Swap \n\
The boot partition will be 512M \n\
The root partition will be the remaining of the hard disk \n\n\
Enter below the partition size (in Gb) for the Swap. \n\n\
If you don't enter anything, it will default to ${default_size}G. \n" \
20 60 2> swap_size
size=$(cat swap_size) && rm swap_size
[[ $size =~ ^[0-9]+$ ]] || size=$default_size
dialog --no-cancel \
--title "!!! DELETE EVERYTHING !!!" \
--menu "Choose the way you'll wipe your hard disk ($hd)" \
15 60 4 \
1 "Use dd (wipe all disk)" \
2 "Use schred (slow & secure)" \
3 "No need - my hard disk is empty" 2> eraser
hderaser=$(cat eraser); rm eraser
# This function can wipe out a hard disk.
# DO NOT RUN THIS FUNCTION ON YOUR ACTUAL SYSTEM!
# If you did it, DO NOT CALL IT!!
# If you did it, I'm sorry.
function eraseDisk() {
case $1 in
1) dd if=/dev/zero of="$hd" status=progress 2>&1 \
| dialog \
--title "Formatting $hd..." \
--progressbox --stdout 20 60;;
2) shred -v "$hd" \
| dialog \
--title "Formatting $hd..." \
--progressbox --stdout 20 60;;
3) ;;
esac
}
eraseDisk "$hderaser"
boot_partition_type=1
[[ "$uefi" == 0 ]] && boot_partition_type=4
# Create the partitions
#g - create non empty GPT partition table
#n - create new partition
#p - primary partition
#e - extended partition
#w - write the table to disk and exit
partprobe "$hd"
fdisk "$hd" << EOF
g
n
+1024M
t
$boot_partition_type
n
+${size}G
n
w
EOF
partprobe "$hd"
# Add a suffix "p" in case with have a NVMe controller chip
echo "$hd" | grep -E 'nvme' &> /dev/null && hd="${hd}p"
# Format the partitions
mkswap "${hd}2"
swapon "${hd}2"
mkfs.ext4 "${hd}3"
mount "${hd}3" /mnt
if [ "$uefi" = 1 ]; then
mkfs.fat -F32 "${hd}1"
mkdir -p /mnt/boot/efi
mount "${hd}1" /mnt/boot/efi
fi
# Install Arch Linux! Glory and fortune!
pacstrap /mnt base base-devel linux linux-firmware
genfstab -U /mnt >> /mnt/etc/fstab
# Persist important values for the next script
echo "$uefi" > /mnt/var_uefi
echo "$hd" > /mnt/var_hd
mv comp /mnt/comp
# Don't forget to replace "benjaminshawki" by the username of your Github account
curl https://raw.githubusercontent.com/benjaminshawki\
/arch_installer/main/install_chroot.sh > /mnt/install_chroot.sh
arch-chroot /mnt bash install_chroot.sh
rm /mnt/var_uefi
rm /mnt/var_hd
rm /mnt/install_chroot.sh
rm /mnt/comp
dialog --title "To reboot or not to reboot?" --yesno \
"Congrats! The install is done! \n\n\
Do you want to reboot your computer?" 20 60
response=$?
case $response in
0) reboot;;
1) clear;;
esac