-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·111 lines (90 loc) · 3.26 KB
/
install.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
#!/bin/sh
# Script to install Arch Linux.
# Uncomment lines below and set values manually.
# drive="" # Drive to install Arch Linux. (default first drive)
# swap_size="" # Swap size in GiB. Set "0" for none. (default "8")
# encrypt_root="" # Encrypt root partition ("true" or "false"). (default "false")
# pass_luks="" # Passphrase for LUKS if encryption is "true". (default "pass")
# pass_root="" # Passphrase for root user. (default "pass")
# username="" # Username for regular user. (default "user")
# pass_user="" # Passphrase for regular user. (default "pass")
# hostname="" # Hostname of the device. (default "arch")
# keymap="" # Keyboard mapping for console. (default "us")
# Set default values.
drive_default="$(lsblk -dno NAME | grep -E '^nvme|^sd|^vd' | head -n 1)"
drive="${drive:-$drive_default}"
swap_size="${swap_size:-8}"
encrypt_root="${encrypt_root:-false}"
pass_luks="${pass_luks:-pass}"
pass_root="${pass_root:-pass}"
username="${username:-user}"
pass_user="${pass_user:-pass}"
hostname="${hostname:-arch}"
keymap="${keymap:-us}"
# Assert file existence.
[ -f chroot.sh ] || exit 1
# Main program following https://wiki.archlinux.org/title/Installation_guide
# Pre-installation
# Verify the boot mode
[ -d /sys/firmware/efi/efivars ] || exit
# Partition the disks
fdisk "/dev/$drive" << FDISK_CMDS
g
n
+1024M
t
1
n
w
FDISK_CMDS
efi_system_partition="$(lsblk -rno NAME "/dev/$drive" | grep "$drive.*1")"
root_partition="$(lsblk -rno NAME "/dev/$drive" | grep "$drive.*2")"
# Format the partitions
mkfs.fat -F 32 "/dev/$efi_system_partition"
if [ "$encrypt_root" = "true" ]; then
printf '%s' "$pass_luks" | cryptsetup luksFormat --key-file - "/dev/$root_partition"
printf '%s' "$pass_luks" | cryptsetup open --key-file - "/dev/$root_partition" root
mkfs.ext4 /dev/mapper/root
else
mkfs.ext4 "/dev/$root_partition"
fi
# Mount the file systems
if [ "$encrypt_root" = "true" ]; then
mount /dev/mapper/root /mnt
else
mount "/dev/$root_partition" /mnt
fi
mount --mkdir "/dev/$efi_system_partition" /mnt/boot
# swap
if [ "$swap_size" -gt 0 ]; then
dd if=/dev/zero of=/mnt/swapfile bs=1GiB count="$swap_size"
chmod 600 /mnt/swapfile
mkswap /mnt/swapfile
swapon /mnt/swapfile
fi
# Installation
# Install essential packages
pacstrap -K /mnt base linux linux-firmware base-devel efibootmgr neovim networkmanager
# Configure the system
# Fstab
genfstab -U /mnt >> /mnt/etc/fstab
# Create and edit "chroot.sh".
uuid_root="$(lsblk -dno UUID "/dev/$root_partition")"
sed -i -E "s/(^drive=$)/\1'$drive'/" chroot.sh
sed -i -E "s/(^encrypt_root=$)/\1'$encrypt_root'/" chroot.sh
sed -i -E "s/(^uuid_root=$)/\1'$uuid_root'/" chroot.sh
sed -i -E "s/(^pass_root=$)/\1'$pass_root'/" chroot.sh
sed -i -E "s/(^username=$)/\1'$username'/" chroot.sh
sed -i -E "s/(^pass_user=$)/\1'$pass_user'/" chroot.sh
sed -i -E "s/(^hostname=$)/\1'$hostname'/" chroot.sh
sed -i -E "s/(^keymap=$)/\1'$keymap'/" chroot.sh
cp chroot.sh /mnt/root/chroot.sh
# Chroot
arch-chroot /mnt /root/chroot.sh
shred -u /mnt/root/chroot.sh
# Reboot
[ "$swap_size" -gt 0 ] && swapoff /mnt/swapfile
umount -R /mnt
[ "$encrypt_root" = "true" ] && cryptsetup close /dev/mapper/root
# Finalize
printf '\033[1mInstallation is done.\n'