-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·264 lines (239 loc) · 7.03 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
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
#!/usr/bin/env bash
set -xeuo pipefail
# Arguments
#
# Required
# FAI_INSTALL_CONFIGURATION_FILES
# Comma-delimited list of file copy specifications. Each specification is a
# source and destination file path, separate by a `:` character.
# FAI_SYSTEMD_ROOT_PASSWORD
# Password for root user.
# FAI_BOOTLDR_BIOS_DEVICES
# Comma-delimited list of block devices to install bootloader to.
# Note: Only used on a BIOS system
#
# Optional
# FAI_INSTALL_ROOT
# Path to mounted root partition for destination media.
# Default: '/mnt/arch'
# FAI_SYSTEMD_LOCALE
# System locale (eg: 'en_US.UTF-8')
# Default: '$LANG'
# FAI_SYSTEMD_KEYMAP
# System keymap (eg: 'us')
# Default: ''
# FAI_SYSTEMD_TIMEZONE
# System timezone (eg: 'America/Los_Angeles')
# Default determined by accessing a geoip endpoint.
# FAI_SYSTEMD_HOSTNAME
# Default: 'arch'
# FAI_SYSTEMD_MACHINE_ID
# System machine id
# Default determined by running `systemd-firstboot`.
# FAI_BOOTLDR_MKINITCPIO_FILES
# Space-delimited list of files to include in initramfs.
# Default: ''
# FAI_BOOTLDR_MKINITCPIO_HOOKS
# Space-delimited list of hooks to include in initramfs.
# Default: ''
# FAI_BOOTLDR_EFI_DIRECTORY
# Default: '/efi'
# Note: Only used on a UEFI system
# FAI_BOOTLDR_CMDLINE_LINUX_DEFAULT
# Custom GRUB default command-line parameters.
# Default: ''
# Note: Not used when in recovery mode.
# FAI_BOOTLDR_CMDLINE_LINUX
# Custom GRUB command-line parameters.
# Default: ''
# FAI_BOOTLDR_PRELOAD_MODULES
# Custom modules to load before invoking the GRUB command-line.
# Default: 'part_gpt part_msdos'
# FAI_BOOTLDR_ENABLE_CRYPTODISK
# Enable GRUB to decrypt the /boot partition.
# Default: ''
detect_uefi=
if [ -d /sys/firmware/efi/efivars ]; then
detect_uefi=yes
fi
install_root="${FAI_INSTALL_ROOT:-/mnt/arch}"
configuration_files="$FAI_INSTALL_CONFIGURATION_FILES"
locale="${FAI_SYSTEMD_LOCALE:-"$LANG"}"
keymap="${FAI_SYSTEMD_KEYMAP:-}"
timezone="${FAI_SYSTEMD_TIMEZONE:-}"
hostname="${FAI_SYSTEMD_HOSTNAME:-arch}"
machine_id="${FAI_SYSTEMD_MACHINE_ID:-}"
root_password="$FAI_SYSTEMD_ROOT_PASSWORD"
mkinitcpio_files="${FAI_BOOTLDR_MKINITCPIO_FILES:-}"
mkinitcpio_hooks="${FAI_BOOTLDR_MKINITCPIO_HOOKS:-}"
if [ -z "$detect_uefi" ]; then
bios_devices="$FAI_BOOTLDR_BIOS_DEVICES"
else
efi_directory="${FAI_BOOTLDR_EFI_DIRECTORY:-/efi}"
fi
grub_cmdline_linux_default="${FAI_BOOTLDR_CMDLINE_LINUX_DEFAULT:-}"
grub_cmdline_linux="${FAI_BOOTLDR_CMDLINE_LINUX:-}"
grub_preload_modules="${FAI_BOOTLDR_PRELOAD_MODULES:-'part_gpt part_msdos'}"
grub_enable_cryptodisk="${FAI_BOOTLDR_ENABLE_CRYPTODISK:-}"
if [ -z "$timezone" ]; then
timezone="$(
echo "$(curl http://ip-api.com/json)" |
sed --expression 's#.*\"timezone\":\"\([^\"]*\)\".*#\1#'
)"
fi
function ensure_file() {
local file
file="$1"
readonly file
mkdir --parents "$(dirname "$file")"
touch "$file"
}
function copy_file() {
local source destination
source="$1"
destination="$2"
readonly source destination
mkdir --parents "$(dirname "$destination")"
cp --dereference --force "$source" "$destination"
}
function populate_file() {
local file content
file="$1"
content="$2"
readonly file content
ensure_file "$file"
echo "$content" >"$file"
}
function replace_lines() {
local file search replace
file="$1"
search="$2"
replace="$3"
readonly file search replace
ensure_file "$file"
sed --expression="s@$search@$replace@g" --in-place "$file"
}
function link_file() {
local source destination
source="$1"
destination="$2"
readonly source destination
mkdir --parents "$(dirname "$destination")"
ln --symbolic --force "$source" "$destination"
}
echo Update system clock
timedatectl set-ntp true
echo Install base system
pacstrap "$install_root" base
echo Copy configuration files
(
IFS=,
for source_and_destination in $configuration_files; do
copy_file \
"$(echo "$source_and_destination" | awk -F: '{print $1}')" \
"$(echo "$source_and_destination" | awk -F: '{print $2}')"
done
)
echo Configure systemd
systemd_firstboot_args=
if [ -z "$locale" ]; then
systemd_firstboot_args+=' --copy-locale'
else
systemd_firstboot_args+=" --locale=$locale"
fi
if [ -z "$keymap" ]; then
systemd_firstboot_args+=' --copy-keymap'
else
systemd_firstboot_args+=" --keymap=$keymap"
fi
if [ -z "$machine_id" ]; then
systemd_firstboot_args+=' --setup-machine-id'
else
systemd_firstboot_args+=" --machine-id=$machine_id"
fi
systemd-firstboot \
$systemd_firstboot_args \
--timezone="$timezone" \
--hostname="$hostname" \
--root-password="$root_password" \
--root="$install_root"
echo Time zone
link_file "/usr/share/zoneinfo/$timezone" "$install_root/etc/localtime"
arch-chroot "$install_root" hwclock --systohc
echo Localization
replace_lines "$install_root/etc/locale.gen" "^#\\($locale.*\\)$" '\1'
arch-chroot "$install_root" locale-gen
populate_file "$install_root/etc/locale.conf" "LANG=$locale"
if [ ! -z "$keymap" ]; then
populate_file "$install_root/etc/vconsole.conf" "KEYMAP=$keymap"
fi
echo Network configuration
hosts="$(
cat <<EOF
127.0.0.1 localhost
::1 localhost
127.0.1.1 $hostname.localdomain $hostname
EOF
)"
populate_file "$install_root/etc/hostname" "$hostname"
populate_file "$install_root/etc/hosts" "$hosts"
if [ ! -z "$mkinitcpio_files" ] || [ ! -z "$mkinitcpio_hooks" ]; then
echo Initramfs
if [ ! -z "$mkinitcpio_files" ]; then
replace_lines \
"$install_root/etc/mkinitcpio.conf" \
'^FILES=(.*)$' \
"FILES=($mkinitcpio_files)"
fi
if [ ! -z "$mkinitcpio_hooks" ]; then
replace_lines \
"$install_root/etc/mkinitcpio.conf" \
'^HOOKS=(.*)$' \
"HOOKS=($mkinitcpio_hooks)"
fi
arch-chroot "$install_root" mkinitcpio -p linux
fi
echo Microcode
if grep --quiet Intel /proc/cpuinfo; then
pacstrap "$install_root" intel-ucode
fi
if grep --quiet AMD /proc/cpuinfo; then
pacstrap "$install_root" amd-ucode
fi
echo Bootloader
pacstrap "$install_root" grub
replace_lines \
"$install_root/etc/default/grub" \
'^GRUB_CMDLINE_LINUX_DEFAULT=".*"$' \
"GRUB_CMDLINE_LINUX_DEFAULT=\"$grub_cmdline_linux_default\""
replace_lines \
"$install_root/etc/default/grub" \
'^GRUB_CMDLINE_LINUX=".*"$' \
"GRUB_CMDLINE_LINUX=\"$grub_cmdline_linux\""
replace_lines \
"$install_root/etc/default/grub" \
'^GRUB_PRELOAD_MODULES=".*"$' \
"GRUB_PRELOAD_MODULES=\"$grub_preload_modules\""
if [ ! -z "$grub_enable_cryptodisk" ]; then
replace_lines \
"$install_root/etc/default/grub" \
'^#GRUB_ENABLE_CRYPTODISK=y$' \
'GRUB_ENABLE_CRYPTODISK=y'
fi
if [ -z "$detect_uefi" ]; then
(
IFS=,
for device in $bios_devices; do
arch-chroot "$install_root" grub-install --target=i386-pc "$device"
done
)
else
pacstrap "$install_root" efibootmgr
arch-chroot "$install_root" grub-install \
--target=x86_64-efi \
--bootloader-id=GRUB \
--efi-directory="$efi_directory" \
--no-nvram
fi
arch-chroot "$install_root" grub-mkconfig -o /boot/grub/grub.cfg
chmod --recursive 0600 "$install_root/boot"