-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuildiso.sh
executable file
·235 lines (207 loc) · 8.67 KB
/
buildiso.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
#!/usr/bin/env bash
# Generate a PVC autoinstaller ISO via live-build
# This ISO makes a number of assumptions about the system and asks
# minimal questions in order to streamline the install process versus
# using a standard Debian intaller ISO. The end system is suitable
# for immediate bootstrapping with the PVC Ansible roles.
fail() {
echo "$@"
exit 1
}
which lb &>/dev/null || fail "This script requires live-build"
sudo -n true &>/dev/null || fail "The user running this script must have sudo privileges."
idir=$( dirname $0 )
pushd ${idir} &>/dev/null
show_help() {
echo -e "PVC install ISO generator"
echo
echo -e " Generates a mostly-automated installer ISO for a PVC node base system via lb."
echo
echo -e "Usage: $0 [-h] [-o <output_filename>] [-u username] [-a]"
echo
echo -e " -h: Display this help message."
echo -e " -o: Create the ISO as <output_filename> instead of the default."
echo -e " -u: Change 'deploy' user to a new username."
echo -e " -c: Change CPU architecture to a new architecture [x86_64/aarch64]."
echo -e " -m: Change the mirror server (default 'https://ftp.debian.org/debian')."
echo -e " -a: Preserve live-build artifacts."
echo -e " -k: Preserve live-build config."
}
while [ $# -gt 0 ]; do
case "${1}" in
-h|\?)
show_help
exit 0
;;
-o)
isofilename="${2}"
shift 2
;;
-u)
deployusername="${2}"
shift 2
;;
-c)
current_arch=$( uname -m )
if [[ ${current_arch} != ${2} ]]; then
case ${2} in
x86_64)
arch="amd64"
arch_config_append="--architecture amd64 --bootloader grub-efi --bootstrap-qemu-arch amd64 --bootstrap-qemu-static /usr/bin/qemu-x86_64-static"
;;
aarch64)
arch="arm64"
arch_config_append="--architecture arm64 --bootloader grub-efi --bootstrap-qemu-arch arm64 --bootstrap-qemu-static /usr/bin/qemu-aarch64-static"
;;
*)
echo "Invalid arch: ${2}"
echo
show_help
exit 1
;;
esac
fi
shift 2
;;
-m)
mirror_server="${2}"
shift 2
;;
-a)
preserve_artifacts='y'
shift
;;
-k)
preserve_livebuild='y'
shift
;;
*)
echo "Invalid option: ${1}"
echo
show_help
exit 1
;;
esac
done
if [[ -z ${arch} ]]; then
arch="amd64"
fi
if [[ -z ${isofilename} ]]; then
isofilename="pvc-installer_$(date +%Y-%m-%d)_${arch}.iso"
fi
if [[ -z ${deployusername} ]]; then
deployusername="deploy"
fi
if [[ -z ${mirror_server} ]]; then
mirror_server="https://ftp.debian.org/debian"
fi
mkdir -p artifacts/lb
pushd artifacts/lb &>/dev/null
echo "Pre-cleaning live-build environment..."
sudo lb clean
echo
echo "Initializing config..."
# Initialize the live-build config
lb config \
--distribution bookworm \
--archive-areas "main contrib non-free-firmware" \
--mirror-bootstrap "${mirror_server}" \
--mirror-chroot-security "http://security.debian.org/debian-security" \
--debconf-frontend readline \
--apt-recommends false \
--debian-installer netinst \
--debian-installer-gui true \
${arch_config_append} || fail "Failed to initialize live-build config"
echo
# Configure the package lists
echo -n "Copying package lists... "
cp ../../templates/installer.list.chroot config/package-lists/installer.list.chroot || fail "Failed to copy critical template file"
cp ../../templates/installer_${arch}.list.chroot config/package-lists/installer_${arch}.list.chroot || fail "Failed to copy critical template file"
cp ../../templates/firmware.list.chroot config/package-lists/firmware.list.chroot || fail "Failed to copy critical template file"
echo "done."
# Add root password hook
echo -n "Copying live-boot templates... "
mkdir -p config/includes.chroot/etc/live/config.conf.d
cat <<EOF > config/includes.chroot/etc/live/config.conf.d/noeject.conf
noeject
EOF
mkdir -p config/includes.chroot/lib/live/boot/
cp ../../templates/9990-initramfs-tools.sh config/includes.chroot/lib/live/boot/9990-initramfs-tools.sh || fail "Failed to copy critical template file"
chmod +x config/includes.chroot/lib/live/boot/9990-initramfs-tools.sh || fail "Failed to copy critical template file"
mkdir -p config/includes.chroot/lib/live/config/
cp ../../templates/2000-remove-root-pw.sh config/includes.chroot/lib/live/config/2000-remove-root-pw.sh || fail "Failed to copy critical template file"
chmod +x config/includes.chroot/lib/live/config/2000-remove-root-pw.sh || fail "Failed to copy critical template file"
echo "done."
# Set root bashrc
echo -n "Copying root bashrc template... "
mkdir -p config/includes.chroot/root
cp ../../templates/root.bashrc config/includes.chroot/root/.bashrc || fail "Failed to copy critical template file"
echo "done."
# Set hostname and resolv.conf
echo -n "Copying networking templates... "
mkdir -p config/includes.chroot/etc
cp ../../templates/hostname config/includes.chroot/etc/hostname || fail "Failed to copy critical template file"
cp ../../templates/resolv.conf config/includes.chroot/etc/resolv.conf || fail "Failed to copy critical template file"
echo "done."
# Set single vty and autologin
echo -n "Copying getty templates... "
mkdir -p config/includes.chroot/etc/systemd/
cp ../../templates/logind.conf config/includes.chroot/etc/systemd/logind.conf || fail "Failed to copy critical template file"
mkdir -p config/includes.chroot/etc/systemd/system/[email protected]
cp ../../templates/getty-override.conf config/includes.chroot/etc/systemd/system/[email protected]/override.conf || fail "Failed to copy critical template file"
mkdir -p config/includes.chroot/etc/systemd/system/[email protected]
cp ../../templates/serial-getty-override.conf config/includes.chroot/etc/systemd/system/[email protected]/override.conf || fail "Failed to copy critical template file"
echo "done."
# Install GRUB config, theme, and splash
echo -n "Copying bootloader (GRUB) templates... "
cp -a /usr/share/live/build/bootloaders/grub-pc config/bootloaders/ || fail "Failed to copy grub-pc bootloader config from host system"
cp ../../templates/grub.cfg config/bootloaders/grub-pc/grub.cfg || fail "Failed to copy critical template file"
cp ../../templates/theme.txt config/bootloaders/grub-pc/live-theme/theme.txt || fail "Failed to copy critical template file"
cp ../../templates/splash.png config/bootloaders/grub-pc/splash.png || fail "Failed to copy critical template file"
echo "done."
# Install module blacklist template
echo -n "Copying module blacklist template... "
mkdir -p config/includes.chroot/etc/modprobe.d
cp ../../templates/blacklist.conf config/includes.chroot/etc/modprobe.d/blacklist.conf || fail "Failed to copy critical template file"
echo "done."
# Install module initramfs requirements (Broadcom NICs)
echo -n "Copying initramfs modules template... "
mkdir -p config/includes.chroot/etc/initramfs-tools
cp ../../templates/modules config/includes.chroot/etc/initramfs-tools/modules || fail "Failed to copy critical template file"
echo "done."
# Install install.sh and detect.py scripts
echo -n "Copying PVC node installer script template... "
cp ../../templates/install.sh config/includes.chroot/install.sh || fail "Failed to copy critical template file"
chmod +x config/includes.chroot/install.sh
cp ../../templates/detect.py config/includes.chroot/detect.py || fail "Failed to copy critical template file"
chmod +x config/includes.chroot/detect.py
echo "done."
# Customize install.sh script
echo -n "Customizing PVC node installer script... "
sed -i "s/XXDATEXX/$(date)/g" config/includes.chroot/install.sh
sed -i "s/XXDEPLOYUSERXX/${deployusername}/g" config/includes.chroot/install.sh
echo "done."
echo
# Build the live image
echo "Building live image..."
sudo lb build || fail "Failed to build live image"
echo
# Move the ISO image out
echo -n "Copying generated ISO to repository root... "
cp live-image-${arch}.hybrid.iso ../../${isofilename}
echo "done."
# Clean up the artifacts
if [[ -z ${preserve_artifacts} ]]; then
echo "Cleaning live-build environment..."
sudo lb clean
fi
popd &>/dev/null
# Clean up the config
if [[ -z ${preserve_livebuild} ]]; then
echo -n "Removing artifacts... "
sudo rm -rf artifacts/lb
echo "done."
fi
echo
echo "Build completed. ISO file: ${isofilename}"
popd &>/dev/null