This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·416 lines (353 loc) · 10.2 KB
/
install
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
#!/bin/bash
# NOTE: Lowercase variables will be exported to a file
set -euo pipefail
# The below files will be forcefully removed when starting this script.
AI_LOG_FILE="Arch-AI.log"
# base linux linux-firmware (maybe sof-firmware and polkit also for wayland shit?)
# Packages that will be installed on the system with pacstrap
# the only things you are allowed to remove here would be git
# removing other things might break the setup procedure
pacstrap_pkgs=(linux linux-firmware base base-devel iwd git go)
# Required packages to run this script
Reqs=(dosfstools fzf arch-install-scripts)
Fzf_Preview="fzf --border --reverse --height 50%"
usage="./$(basename "$0") [<flags>] -- Automatic Arch Linux install script
Flags:
-h, --help show this help text
-s, --silent don't show which commands are being run
-v, --verbose enable showing the output of the commands"
read_arguments() {
while (("$#")); do
case "$1" in
-v | --verbose)
verbose=true
;;
-s | --silent)
silent=true
;;
-h | --help)
echo "$usage"
exit 0
;;
*)
echo "Error: Unsupported flag $1" >&2
echo "$usage"
exit 1
;;
esac
shift
done
}
# Obtain information about the system
# the script is running on
system_check() {
local gpu
[ "$EUID" -ne 0 ] &&
prompt "This script must be run as root" error &&
exit 1
prompt "Checking for UEFI" work
if [ ! -r /sys/firmware/efi/fw_platform_size ]; then
prompt "Arch not booted into UEFI mode" error
exit 1
fi
prompt "Identifying GPU drivers" work
# https://wiki.archlinux.org/index.php/Xorg#Installation
# https://wiki.archlinux.org/index.php/Hardware_video_acceleration
while read -r gpu; do
case "$gpu" in
# https://wiki.archlinux.org/index.php/Intel_graphics
*"intel"*)
prompt "Intel GPU found" green
add_pkg mesa
add_pkg vulkan-intel
# HW acceleration
add_pkg intel-media-driver
add_pkg libva-intel-driver
# 2D acceleration in Xorg
add_pkg xf86-video-intel
;;
# https://wiki.archlinux.org/index.php/AMDGPU
*"amd"*)
prompt "AMD GPU found" green
add_pkg mesa
add_pkg amdvlk
# HW acceleration
add_pkg libva-mesa-driver
add_pkg mesa-vdpau
# 2D acceleration in Xorg
add_pkg xf86-video-amdgpu
;;
# https://wiki.archlinux.org/index.php/NVIDIA
*"nvidia"*)
prompt "Nvidia GPU found" green
add_pkg nvidia
add_pkg nvidia-utils
# HW acceleration
add_pkg libva-mesa-driver
add_pkg mesa-vdpau
;;
esac
done < <(lspci | grep -e VGA -e 3D | tr '[:upper:]' '[:lower:]')
}
# Installs missing requirements for this script (if any)
# and updates the mirrorlist if needed
installReqs() {
prompt "Upgrading package database" work
out pacman -Sy
if ! grep -qi "generated by reflector" /etc/pacman.d/mirrorlist; then
prompt "Installing reflector" work
out pacman -S reflector --needed --noconfirm
prompt "Generating new pacman mirrors, please be patient" work
out reflector --verbose --latest 15 --sort rate --save /etc/pacman.d/mirrorlist
fi
prompt "Installing additional packages if required" work
out pacman -S "${Reqs[@]}" --needed --noconfirm
}
# Get username, hostname, password, locale
get_config() {
local locale_list
locale_list="$(grep UTF-8 /etc/locale.gen | awk '{print $1}' | cut -c 2-)"
while [[ -z ${AI_LOCALE:-} ]]; do
prompt "Which locale would you like to use?" question
AI_LOCALE=$(echo "$locale_list" | $Fzf_Preview)
done
while true; do
prompt "What hostname would you like: " question true
read -r AI_HOSTNAME
prompt "What username would you like: " question true
read -r AI_USER
[[ -n ${AI_USER:-} && -n ${AI_HOSTNAME:-} ]] && break
prompt "Username or hostname was left blank, try again" error
done
# Get user password
prompt "What password would you like for ${AI_USER}: " question true
read -rs AI_PASS
echo
# Get root password
prompt "What password would you like for the root user: " question true
read -rs AI_ROOT_PASS
echo
}
# Asks the user if they want microcode updates
# and installs it if that is the case
# https://wiki.archlinux.org/title/microcode
# TODO edit bootolader config
get_micro() {
! Ynprompt "Would you like to install microcode updates for your CPU?" && return
prompt "Identifying the CPU drivers" work
case "$(grep vendor /proc/cpuinfo | tr '[:upper:]' '[:lower:]')" in
*"intel"*)
prompt "Intel CPU found" green
add_pkg intel-ucode
;;
# TODO, no clue AMD processors contains "AMD" in vendor_id
*"amd"*)
prompt "AMD CPU found" green
add_pkg amd-ucode
;;
esac
}
# https://wiki.archlinux.org/index.php/Solid_state_drive#TRIM
# shellcheck disable=SC2034
get_misc() {
if Ynprompt "Would you like to install yay?"; then
AI_OPT_YAY=true
fi
if Ynprompt "Would you like to auto-trim your mounted SSDs once a week?"; then
AI_OPT_SSD_TRIM=true
add_pkg util-linux
fi
if Ynprompt "Would you like to enable kernel parameters to allow for hibernation?"; then
AI_OPT_HIBERNATION=true
fi
if Ynprompt "Would you like to enable parallel and optimized compilation&compression for makepkg?"; then
AI_OPT_MAKEPKG=true
fi
}
# Ask for some additional popular packages
get_pkgs() {
prompt "Would you like to install any additional packages? (Use <Tab>)" question
for choice in $(pacman -Slq | fzf -m --preview 'pacman -Si {1}' || true); do
add_pkg "$choice"
done
}
# Adds a package to be pacstrapped
add_pkg() {
# Add package to list if not already there
if [[ ${pacstrap_pkgs[*]} != *$1* ]]; then
pacstrap_pkgs+=("$1")
fi
}
# Asks which drive arch should be installed to
get_drive() {
local drives numDrives choice
local re='^[0-9]+$'
lsblk
echo
drives=$(find /dev/sd*[a-z] | sort)
numDrives=$(echo "$drives" | wc -w)
echo "$drives" | awk '{print NR,$0}'
while ! [[ ${choice:-} =~ $re ]] || [[ ${choice:-} -le 0 || ${choice:-} -gt $numDrives ]]; do
prompt "Which drive would you like to install Arch on [1-$numDrives]: " question true
read -r choice
done
# fs contains the base path to the drive
# such as /dev/sda
fs=$(echo "$drives" | sed -n "$choice"p)
if [[ -z $fs ]]; then
prompt "Something went wrong" error
exit 1
fi
while ! [[ ${swapSize:-} =~ $re ]]; do
prompt "How big should the swap partition be [GB]: " question true
read -r swapSize
done
while ! [[ ${rootSize:-} =~ $re ]]; do
prompt "Type 0 to fill the remaining space on the disk selected" note
prompt "How big should the root partition be [GB]: " question true
read -r rootSize
done
# Set formatting of the variables
# so that fdisk can use them
swapSize="+${swapSize}G"
[[ $rootSize != 0 ]] && rootSize="+${rootSize}G"
# Setup paths to the different
# partitions on the hard drive
AI_BOOT_PARTITION="${fs}"1
AI_SWAP_PART="${fs}"2
root="${fs}"3
}
verify() {
echo "Username: $AI_USER
Hostname: $AI_HOSTNAME
Locale: $AI_LOCALE
Installation drive: $fs
Root partition: $rootSize
Swap partition: $swapSize
Packages: ${pacstrap_pkgs[*]}"
read -rn 1 -p "Continue with install? (y/N)" && [[ ! $REPLY =~ ^[Yy]$ ]] &&
prompt "Installation cancelled" error && exit
echo
}
set_ntp() {
out timedatectl set-ntp true # Enable Network Time Protocol (NTP) synchronization
}
# 1=bootloader, 2=swap, 3=root
setup_fs() {
while swapon --show | grep -q "$fs"; do
prompt "$fs seems to have a swap partition, trying to disable it" error
swapoff "$(swapon --show | grep "$fs" | awk '{print $1}')"
done
while df | grep -q "$fs"; do
prompt "$fs seems to have some partion(s) mounted, trying to unmount" error
ls "$fs"?* | xargs -n1 umount -l
sleep 1
done
# Wipe drive
out wipefs -af "$fs"
prompt "Creating partitions" work
(
# GPT > MBR
echo g
mkpart "+512M"
# Set partition type to 'EFI System'
echo t
echo 1
mkpart "$swapSize"
# Set partition type to 'Linux AI_SWAP_PART'
echo t
echo 2
echo 19
# Either fill the rest of the drive, or the chosen amount
([[ $rootSize -eq 0 ]] && mkpart) || mkpart "$rootSize"
# Set partition type to 'Linux root (x86-64)'
echo t
echo 3
echo 23
echo w
) | out fdisk "$fs"
prompt "Formatting partitions" work
out mkfs.fat -F32 "$AI_BOOT_PARTITION"
out mkswap -L SWAP_PARTITION "$AI_SWAP_PART"
out swapon "$AI_SWAP_PART"
out mkfs.ext4 -F "$root"
prompt "Setting partition labels" work
out e2label "$root" ROOT_PARTITION
prompt "Enabling fast_commit on ext4 filesystems" work
out tune2fs -O fast_commit "$root"
prompt "Mounting $root" work
out mount "$root" /mnt
prompt "Mounting $AI_BOOT_PARTITION" work
out mount --mkdir "$AI_BOOT_PARTITION" /mnt/boot
}
# sequence for creating a new partition
# 1: size of partition (leave empty to fill)
mkpart() {
echo n
echo
echo
echo "${1:-}"
}
arch_install() {
prompt "The script will now install and set up your system" green
prompt "No further input will be needed" green
prompt "pacstrap_pkgsping packages" work
pacstrap /mnt "${pacstrap_pkgs[@]}"
# not in guide
out umount /mnt/boot # We don't want this in the fstab
prompt "Generating the fstab" work
genfstab -U /mnt >/mnt/etc/fstab
out mount "$AI_BOOT_PARTITION" /mnt/boot
}
# chroot into the new arch installation
jumpChroot() {
(
set -o posix
set
) | grep '^AI' >/mnt/info
cp setup /mnt/setup
cp sharedfuncs /mnt/sharedfuncs
chmod 554 /mnt/setup
# Move files to the new arch installation
mv "$AI_LOG_FILE" /mnt/
AI_LOG_FILE="/$AI_LOG_FILE"
# Launch the setup script
arch-chroot /mnt /bin/bash <<EOF
./setup
rm setup
rm sharedfuncs
EOF
}
# Y/n prompt, returns 0 if answer is anything except n or N
# 1: message
Ynprompt() {
prompt "$1 (Y/n) " question true
read -rn 1
if [[ $REPLY =~ ^[Nn]$ ]]; then
echo -e "\e[1Dn"
return 1
else
echo -e "\e[1DY"
return 0
fi
}
main() {
source sharedfuncs
# Remove files from previous runs
rm -f "$AI_LOG_FILE"
read_arguments "$@"
system_check
set_ntp
installReqs
get_config
get_micro
get_misc
get_pkgs
get_drive
verify
setup_fs
arch_install
jumpChroot
prompt "Arch Linux successfully installed" green
}
main "$@"