-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharch-install.sh
executable file
·272 lines (227 loc) · 9.72 KB
/
arch-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
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
#!/bin/bash
set -e
cd "$(dirname "$(realpath "$0")")" || return
# VARIABLES {{{
HOST=${1:-NOT_SET}
STAGE=${2:-NOT_SET}
SCRIPT_DIR=$(pwd)
MIRRORS=()
source ./global-variables.sh
# shellcheck source=host-variables/_template.sh
source "./host-variables/${HOST}.sh"
# }}}
# HELPER FUNCTIONS {{{
info() {
printf "%s\n" "$*"
}
wait_to_continue() {
info "Press any key to continue"
read -r -n 1
info "\n\n\n"
}
# }}}
# INSTALL
case $STAGE in
PRE-INSTALL|INSTALL) # {{{
# setup mirrorlist {{{
if [ ${#MIRRORS[@]} -gt 0 ]; then
rm -f /etc/pacman.d/mirrorlist
for MIRROR in "${MIRRORS[@]}"; do
echo "Server = $MIRROR" >> /etc/pacman.d/mirrorlist
done
fi
echo "Mirrors:"
cat /etc/pacman.d/mirrorlist
sed -i "s/#ParallelDownloads = 5/ParallelDownloads = ${PARALLEL_DOWNLOADS:-5}/" /etc/pacman.conf
# }}}
# set-ntp {{{
timedatectl set-ntp true
# }}}
# partitions {{{
# shellcheck disable=SC2114
rm -rf "/mnt/*"
# script from: https://superuser.com/a/984637
TOTAL_MEMORY=$(awk '/MemTotal/ {printf "%3.0f", ($2/1024000)}' /proc/meminfo)
SWAP_SIZE=${SWAP_SIZE:-$TOTAL_MEMORY}
if [ "$EFI" = true ]; then
# EFI {{{
(
# fdisk {{{
echo g # clear the in memory partition table
echo n # new partition
echo # Select next partition number
echo # default - start at beginning of disk
echo +512M # 512 MB boot parttion (EFI)
echo y # in case the signature already exists, this will remove the previous signature
echo t # partition type
echo # partition 1
echo 1 # EFI
echo n # new partition
echo # Select next partition number
echo # default, start immediately after preceding partition
echo "+${SWAP_SIZE}G" # Set Swap size
echo y # in case the signature already exists, this will remove the previous signature
echo t # partition type
echo # partition 2
echo 19 # SWAP
echo n # new partition
echo # Select next partition number
echo # default, start immediately after preceding partition
echo # Set root to use remaining disk size
echo y # in case the signature already exists, this will remove the previous signature
echo t # partition type
echo # partition 2
echo 24 # ROOT
echo p # print the in-memory partition table
echo w # write the partition table
# }}}
) | fdisk "${TGTDEV}"
if [[ ${TGTDEV: -1} =~ [0-9] ]]; then
# Sets up the partition device naming (ex. with nvme drives named: /dev/nvme0n1)
TGTDEV="${TGTDEV}p"
fi
# create filesystem and swap
mkfs.fat -F32 "${TGTDEV}1"
mkswap -L SWAP "${TGTDEV}2"
swapon "${TGTDEV}2"
mkfs.ext4 -F "${TGTDEV}3"
e2label "${TGTDEV}3" ROOT
# mount all the partitions
mount "${TGTDEV}3" /mnt
mkdir -p /mnt/boot
mount "${TGTDEV}1" /mnt/boot
# }}}
else
# MBR {{{
(
# fdisk {{{
echo o # clear the in memory partition table
echo n # new partition
echo p # primary partition type
echo # Select next partition number
echo # default, start immediately after preceding partition
echo "+${SWAP_SIZE}G" # Set Swap size
echo y # in case the signature already exists, this will remove the previous signature
echo n # new partition
echo p # primary partition type
echo # Select next partition number
echo # default, start immediately after preceding partition
echo # Set root to use remaining disk size
echo y # in case the signature already exists, this will remove the previous signature
echo t # partition type
echo 1 # partition 2
echo 83 # Linux
echo t # partition type
echo 2 # partition 3
echo 82 # SWAP
echo p # print the in-memory partition table
echo w # write the partition table
# }}}
) | fdisk "${TGTDEV}"
if [[ ${TGTDEV: -1} =~ [0-9] ]]; then
# Sets up the partition device naming (ex. with nvme drives named: /dev/nvme0n1)
TGTDEV="${TGTDEV}p"
fi
# create filesystem and swap
mkswap -L SWAP "${TGTDEV}1"
swapon "${TGTDEV}1"
mkfs.ext4 -F "${TGTDEV}2"
e2label "${TGTDEV}2" ROOT
# mount all the partitions
mount "${TGTDEV}2" /mnt
# }}}
fi
# }}}
# pacstrap {{{
KEYRING_INITIALIZING="$(mktemp)"
echo "Waiting for arch-keyring to initialize"
for _ in {1..300}; do
systemctl show pacman-init.service | \
grep -q 'SubState=exited' && \
rm -f "$KEYRING_INITIALIZING" && \
break
sleep 1
done
if [ -f "$KEYRING_INITIALIZING" ]; then
echo "Keyring did not initialize, aborting!"
exit 1
fi
yes | pacman -Sy archlinux-keyring
pacstrap -K /mnt "${PACKAGES[@]}"
# }}}
# genfstab {{{
genfstab -U /mnt >> /mnt/etc/fstab
# }}}
# arch-chroot {{{
OUT_FOLDER=$(basename "${SCRIPT_DIR}")
cp -r "${SCRIPT_DIR}" "/mnt/${OUT_FOLDER}"
arch-chroot /mnt "/${OUT_FOLDER}/arch-install.sh" "${HOST}" ARCH-CHROOT
cp -r ~/.ssh /mnt/root/
# cleanup
rm -r "/mnt/${OUT_FOLDER:?}"
umount /mnt/boot
umount /mnt/
# }}}
;; # }}}
ARCH-CHROOT) # {{{
# date time {{{
ln -sf "/usr/share/zoneinfo/${TIMEZONE}" /etc/localtime
hwclock --systohc
# }}}
# locale {{{
cp /etc/locale.gen /tmp/locale.gen
for LOCALE in "${LOCALES[@]}"; do
sed -i "s/#${LOCALE}/${LOCALE}/" /etc/locale.gen
done
locale-gen
cat <<-EOF > /etc/locale.conf
LANG=${LOCALE_CONF_LANG:-en_GB.UTF-8}
LC_TIME=${LOCALE_CONF_LC_TIME:-en_GB.UTF-8}
EOF
echo "KEYMAP=${KEYMAP}" > /etc/vconsole.conf
# }}}
# hostname {{{
echo "${HOSTNAME}" > /etc/hostname
cat <<-EOF > /etc/hosts
127.0.0.1 localhost
::1 localhost
127.0.1.1 ${HOSTNAME}.${DOMAIN} ${HOSTNAME}
EOF
# }}}
# initfsram{{{
mkinitcpio -P
# }}}
# bootloader {{{
if [ "$EFI" = true ]; then
bootctl --path=/boot/ install
cat <<-EOF > /boot/loader/entries/arch.conf
title Arch Linux
linux /vmlinuz-linux
initrd /${MICROCODE}.img
initrd /initramfs-linux.img
options root=LABEL=ROOT resume=LABEL=SWAP rw
EOF
else
grub-install "${TGTDEV}"
grub-mkconfig -o /boot/grub/grub.cfg
fi
# }}}
# root password{{{
echo root:password | chpasswd
# }}}
# enable systemd-networkd with enabled DHCP {{{
cat <<-EOF > /etc/systemd/network/ethernet.network
[Match]
Name=*
[Network]
DHCP=ipv4
Domains=local
EOF
systemctl enable systemd-networkd
systemctl enable systemd-resolved
# }}}
# enable systemd-networkd with enabled DHCP {{{
systemctl enable sshd
# }}}
;; # }}}
esac