This repository was archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpre.sh
More file actions
579 lines (509 loc) · 28.1 KB
/
pre.sh
File metadata and controls
579 lines (509 loc) · 28.1 KB
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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2019-2021 Intel Corporation
set -a
# this is provided while using uOS
# shellcheck source=/dev/null
source /opt/bootstrap/functions
# --- Ubuntu Packages ---
ubuntu_packages="net-tools shim-signed"
ubuntu_tasksel="standard"
start=$(date +%s)
export start
PROVISION_LOG="/tmp/provisioning.log"
run "Begin provisioning process..." \
"echo \"Begin provisioning process with following params: \$(cat /proc/cmdline)\" && \
while (! docker ps > /dev/null ); do sleep 0.5; done" \
"${PROVISION_LOG}"
PROVISIONER=$1
# --- Get kernel parameters ---
kernel_params=$(cat /proc/cmdline)
if [[ $kernel_params == *"ntp_server"* ]]; then
tmp="${kernel_params##*ntp_server=}"
export param_ntp="${tmp%% *}"
else
export param_ntp="us.pool.ntp.org"
fi
run "Trying to sync time with ${param_ntp}..." \
"ntpd -d -N -q -n -p ${param_ntp} || true" \
"${PROVISION_LOG}"
if [[ $kernel_params == *"proxy="* ]]; then
tmp="${kernel_params##*proxy=}"
export param_proxy="${tmp%% *}"
export http_proxy=${param_proxy}
export https_proxy=${param_proxy}
export no_proxy="localhost,127.0.0.1,${PROVISIONER}"
export HTTP_PROXY=${param_proxy}
export HTTPS_PROXY=${param_proxy}
export NO_PROXY="localhost,127.0.0.1,${PROVISIONER}"
export DOCKER_PROXY_ENV="--env http_proxy='${http_proxy}' --env https_proxy='${https_proxy}' --env no_proxy='${no_proxy}' --env HTTP_PROXY='${HTTP_PROXY}' --env HTTPS_PROXY='${HTTPS_PROXY}' --env NO_PROXY='${NO_PROXY}'"
export INLINE_PROXY="export http_proxy='${http_proxy}'; export https_proxy='${https_proxy}'; export no_proxy='${no_proxy}'; export HTTP_PROXY='${HTTP_PROXY}'; export HTTPS_PROXY='${HTTPS_PROXY}'; export NO_PROXY='${NO_PROXY}';"
elif nc -vz -w 2 "${PROVISIONER}" 3128 && nc -vz -w 2 "${PROVISIONER}" 4128; then
PROXY_DOCKER_BIND="-v /tmp/ssl:/etc/ssl/ -v /usr/local/share/ca-certificates/EB.pem:/usr/local/share/ca-certificates/EB.crt"
export http_proxy=http://${PROVISIONER}:3128/
export https_proxy=http://${PROVISIONER}:4128/
export no_proxy="localhost,127.0.0.1,${PROVISIONER}"
export HTTP_PROXY=http://${PROVISIONER}:3128/
export HTTPS_PROXY=http://${PROVISIONER}:4128/
export NO_PROXY="localhost,127.0.0.1,${PROVISIONER}"
export DOCKER_PROXY_ENV="--env http_proxy='${http_proxy}' --env https_proxy='${https_proxy}' --env no_proxy='${no_proxy}' --env HTTP_PROXY='${HTTP_PROXY}' --env HTTPS_PROXY='${HTTPS_PROXY}' --env NO_PROXY='${NO_PROXY}' ${PROXY_DOCKER_BIND}"
export INLINE_PROXY="export http_proxy='${http_proxy}'; export https_proxy='${https_proxy}'; export no_proxy='${no_proxy}'; export HTTP_PROXY='${HTTP_PROXY}'; export HTTPS_PROXY='${HTTPS_PROXY}'; export NO_PROXY='${NO_PROXY}'; if [ ! -f /usr/local/share/ca-certificates/EB.crt ]; then if (! which wget > /dev/null ); then apt update && apt -y install wget; fi; wget -O - http://${PROVISIONER}/squid-cert/CA.pem > /usr/local/share/ca-certificates/EB.crt && update-ca-certificates; fi;"
wget -O - "http://${PROVISIONER}/squid-cert/CA.pem" > /usr/local/share/ca-certificates/EB.pem
update-ca-certificates
elif nc -vz -w 2 "${PROVISIONER}" 3128; then
export http_proxy=http://${PROVISIONER}:3128/
export https_proxy=http://${PROVISIONER}:3128/
export no_proxy="localhost,127.0.0.1,${PROVISIONER}"
export HTTP_PROXY=http://${PROVISIONER}:3128/
export HTTPS_PROXY=http://${PROVISIONER}:3128/
export NO_PROXY="localhost,127.0.0.1,${PROVISIONER}"
export DOCKER_PROXY_ENV="--env http_proxy='${http_proxy}' --env https_proxy='${https_proxy}' --env no_proxy='${no_proxy}' --env HTTP_PROXY='${HTTP_PROXY}' --env HTTPS_PROXY='${HTTPS_PROXY}' --env NO_PROXY='${NO_PROXY}'"
# shellcheck disable=SC2089
export INLINE_PROXY="export http_proxy='${http_proxy}'; export https_proxy='${https_proxy}'; export no_proxy='${no_proxy}'; export HTTP_PROXY='${HTTP_PROXY}'; export HTTPS_PROXY='${HTTPS_PROXY}'; export NO_PROXY='${NO_PROXY}';"
fi
if [[ $kernel_params == *"proxysocks="* ]]; then
tmp="${kernel_params##*proxysocks=}"
param_proxysocks="${tmp%% *}"
export FTP_PROXY=${param_proxysocks}
tmp_socks=$(echo "${param_proxysocks}" | sed "s#http://##g" | sed "s#https://##g" | sed "s#/##g")
export SSH_PROXY_CMD="-o ProxyCommand='nc -x ${tmp_socks} %h %p'"
fi
if [[ $kernel_params == *"wifissid="* ]]; then
tmp="${kernel_params##*wifissid=}"
export param_wifissid="${tmp%% *}"
elif [ -n "${SSID}" ]; then
export param_wifissid="${SSID}"
fi
if [[ $kernel_params == *"wifipsk="* ]]; then
tmp="${kernel_params##*wifipsk=}"
export param_wifipsk="${tmp%% *}"
elif [ -n "${PSK}" ]; then
export param_wifipsk="${PSK}"
fi
if [[ $kernel_params == *"network="* ]]; then
tmp="${kernel_params##*network=}"
export param_network="${tmp%% *}"
fi
if [[ $kernel_params == *"httppath="* ]]; then
tmp="${kernel_params##*httppath=}"
export param_httppath="${tmp%% *}"
fi
if [[ $kernel_params == *"parttype="* ]]; then
tmp="${kernel_params##*parttype=}"
export param_parttype="${tmp%% *}"
elif [ -d /sys/firmware/efi ]; then
export param_parttype="efi"
else
export param_parttype="msdos"
fi
if [[ $kernel_params == *"bootstrap="* ]]; then
tmp="${kernel_params##*bootstrap=}"
export param_bootstrap="${tmp%% *}"
export param_bootstrapurl=${param_bootstrap//$(basename "$param_bootstrap")/}
fi
if [[ $kernel_params == *"token="* ]]; then
tmp="${kernel_params##*token=}"
export param_token="${tmp%% *}"
fi
if [[ $kernel_params == *"agent="* ]]; then
tmp="${kernel_params##*agent=}"
export param_agent="${tmp%% *}"
else
export param_agent="master"
fi
if [[ $kernel_params == *"kernparam="* ]]; then
tmp="${kernel_params##*kernparam=}"
temp_param_kernparam="${tmp%% *}"
param_kernparam=$(echo "${temp_param_kernparam}" | sed 's/#/ /g' | sed 's/:/=/g')
export param_kernparam
fi
if [[ $kernel_params == *"ubuntuversion="* ]]; then
tmp="${kernel_params##*ubuntuversion=}"
export param_ubuntuversion="${tmp%% *}"
else
export param_ubuntuversion="cosmic"
fi
# The following is bandaid for Disco Dingo
if [ $param_ubuntuversion = "disco" ]; then
export DOCKER_UBUNTU_RELEASE="cosmic"
else
export DOCKER_UBUNTU_RELEASE=$param_ubuntuversion
fi
if [[ $kernel_params == *"arch="* ]]; then
tmp="${kernel_params##*arch=}"
export param_arch="${tmp%% *}"
else
export param_arch="amd64"
fi
if [[ $kernel_params == *"kernelversion="* ]]; then
tmp="${kernel_params##*kernelversion=}"
export param_kernelversion="${tmp%% *}"
else
export param_kernelversion="linux-image-generic"
fi
if [[ $kernel_params == *"insecurereg="* ]]; then
tmp="${kernel_params##*insecurereg=}"
export param_insecurereg="${tmp%% *}"
fi
if [[ $kernel_params == *"username="* ]]; then
tmp="${kernel_params##*username=}"
export param_username="${tmp%% *}"
else
export param_username="sys-admin"
fi
if [[ $kernel_params == *"password="* ]]; then
tmp="${kernel_params##*password=}"
export param_password="${tmp%% *}"
else
msg="The password was not set"
run "${msg}" "echo ${msg} - This is not supported; false" "${PROVISION_LOG}"
fi
if [[ $kernel_params == *"bare_os="* ]]; then
tmp="${kernel_params##*bare_os=}"
export param_bare_os="${tmp%% *}"
else
export param_bare_os="false"
fi
if [[ $param_bare_os == "true" ]]; then
export param_validationmode=true
else
export param_validationmode=false
fi
if [[ $kernel_params == *"debug="* ]]; then
tmp="${kernel_params##*debug=}"
export param_debug="${tmp%% *}"
export debug="${tmp%% *}"
fi
if [[ $kernel_params == *"release="* ]]; then
tmp="${kernel_params##*release=}"
export param_release="${tmp%% *}"
else
export param_release='dev'
fi
if [[ $kernel_params == *"docker_login_user="* ]]; then
tmp="${kernel_params##*docker_login_user=}"
export param_docker_login_user="${tmp%% *}"
fi
if [[ $kernel_params == *"docker_login_pass="* ]]; then
tmp="${kernel_params##*docker_login_pass=}"
export param_docker_login_pass="${tmp%% *}"
fi
if [[ $param_release == 'prod' ]]; then
export kernel_params="$param_kernparam" # ipv6.disable=1
else
export kernel_params="$param_kernparam"
fi
if [[ $kernel_params == *"mirror="* ]]; then
tmp="${kernel_params##*mirror=}"
export param_mirror="${tmp%% *}"
elif wget -q --method=HEAD "http://${PROVISIONER}${param_httppath}/build/dists/${param_ubuntuversion}/InRelease"; then
export param_mirror="http://${PROVISIONER}${param_httppath}/build"
elif wget -q --method=HEAD "http://${PROVISIONER}${param_httppath}/distro/dists/${param_ubuntuversion}/InRelease"; then
export param_mirror="http://${PROVISIONER}${param_httppath}/distro"
fi
if [ -n "${param_mirror}" ]; then
export PKG_REPO_LIST=""
if wget -q --method=HEAD "${param_mirror}/dists/${param_ubuntuversion}/main/binary-${param_arch}/Release"; then
export PKG_REPO_LIST="${PKG_REPO_LIST} main"
fi
if wget -q --method=HEAD "${param_mirror}/dists/${param_ubuntuversion}/restricted/binary-${param_arch}/Release"; then
export PKG_REPO_LIST="${PKG_REPO_LIST} restricted"
fi
if wget -q --method=HEAD "${param_mirror}/dists/${param_ubuntuversion}/universe/binary-${param_arch}/Release"; then
export PKG_REPO_LIST="${PKG_REPO_LIST} universe"
fi
if wget -q --method=HEAD "${param_mirror}/dists/${param_ubuntuversion}/multiverse/binary-${param_arch}/Release"; then
export PKG_REPO_LIST="${PKG_REPO_LIST} multiverse"
fi
export PKG_REPO_SEC_LIST=""
if wget -q --method=HEAD "${param_mirror}/dists/${param_ubuntuversion}-security/main/binary-${param_arch}/Release"; then
export PKG_REPO_SEC_LIST="${PKG_REPO_SEC_LIST} main"
fi
if wget -q --method=HEAD "${param_mirror}/dists/${param_ubuntuversion}-security/restricted/binary-${param_arch}/Release"; then
export PKG_REPO_SEC_LIST="${PKG_REPO_SEC_LIST} restricted"
fi
if wget -q --method=HEAD "${param_mirror}/dists/${param_ubuntuversion}-security/universe/binary-${param_arch}/Release"; then
export PKG_REPO_SEC_LIST="${PKG_REPO_SEC_LIST} universe"
fi
if wget -q --method=HEAD "${param_mirror}/dists/${param_ubuntuversion}-security/multiverse/binary-${param_arch}/Release"; then
export PKG_REPO_SEC_LIST="${PKG_REPO_SEC_LIST} multiverse"
fi
fi
# --- Run Partitioner ---
# shellcheck source=create_seo_partitions.sh
source <(wget --header "Authorization: token ${param_token}" -O- "${param_bootstrapurl}/create_seo_partitions.sh")
# --- Get free memory
freemem=$(grep MemTotal /proc/meminfo | awk '{print $2}')
export freemem
# --- check if we need to move tmp folder ---
if [ "$freemem" -lt 6291456 ]; then
mkdir -p $ROOTFS/tmp
export TMP=$ROOTFS/tmp
else
export TMP=/tmp
fi
export PROVISION_LOG="$TMP/provisioning.log"
if wget "http://${PROVISIONER}:5557/v2/_catalog" -O- 2>/dev/null; then
export REGISTRY_MIRROR="--registry-mirror=http://${PROVISIONER}:5557"
elif wget "http://${PROVISIONER}:5000/v2/_catalog" -O- 2>/dev/null; then
export REGISTRY_MIRROR="--registry-mirror=http://${PROVISIONER}:5000"
fi
# -- Configure Image database ---
run "Configuring Image Database" \
"mkdir -p $ROOTFS/tmp/docker && \
chmod 777 $ROOTFS/tmp && \
killall dockerd && sleep 2 && \
/usr/local/bin/dockerd ${REGISTRY_MIRROR} --data-root=$ROOTFS/tmp/docker > /dev/null 2>&1 &" \
"${PROVISION_LOG}"
while (! docker ps > /dev/null ); do sleep 0.5; done; sleep 3
if [ -n "${param_docker_login_user}" ] && [ -n "${param_docker_login_pass}" ]; then
run "Log in to a Docker registry" \
"docker login -u ${param_docker_login_user} -p ${param_docker_login_pass}" \
"${PROVISION_LOG}"
fi
# shellcheck source=./files/seo/provision_settings
source <(wget --header "Authorization: token ${param_token}" -O- "${param_bootstrapurl}/files/seo/provision_settings")
# try to find mac specific file for node
for mac in $(ip a | grep ether | awk '{print $2}')
do
if wget --header "Authorization: token ${param_token}" -S --spider "${param_bootstrapurl}/files/seo/provision_settings_${mac}" 2>&1 | grep -q 'HTTP/1.1 200 OK'; then
wget --header "Authorization: token ${param_token}" "${param_bootstrapurl}/files/seo/provision_settings_${mac}"
NODE_SETTINGS="$(pwd)/provision_settings_${mac}"
# overrides redfish variable taken from provision_settings
# shellcheck source=./files/seo/provision_settings_mac
source "${NODE_SETTINGS}"
run "Found NODE_SETTINGS file for machine mac: ${mac}" \
"echo NODE_SETTINGS; cat ${NODE_SETTINGS}" \
"${PROVISION_LOG}"
break
fi
done
# --- Begin Ubuntu Install Process ---
run "Preparing Ubuntu ${param_ubuntuversion} installer" \
"docker pull ubuntu:${param_ubuntuversion}" \
"${PROVISION_LOG}"
rootfs_partuuid=$(lsblk -no UUID "${ROOT_PARTITION}")
bootfs_partuuid=$(lsblk -no UUID "${BOOT_PARTITION}")
if [[ $param_parttype == 'efi' ]]; then
run "Installing Ubuntu ${param_ubuntuversion} (~10 min)" \
"docker run -i --rm --privileged --name ubuntu-installer ${DOCKER_PROXY_ENV} -v $ROOTFS:/target/root ubuntu:${param_ubuntuversion} sh -c \
'if [ \"${PKG_REPO_LIST}\" != \"\" ]; then echo \"deb ${param_mirror} ${param_ubuntuversion} ${PKG_REPO_LIST}\" > /etc/apt/sources.list; fi && \
if [ \"${PKG_REPO_SEC_LIST}\" != \"\" ]; then echo \"deb ${param_mirror} ${param_ubuntuversion}-security ${PKG_REPO_SEC_LIST}\" >> /etc/apt/sources.list; fi && \
apt update && \
apt install -y debootstrap && \
debootstrap --arch ${param_arch} ${param_ubuntuversion} /target/root ${param_mirror} && \
if [ -z ${param_mirror} ]; then cp /etc/apt/sources.list /target/root/etc/apt/sources.list; fi && \
if [ \"${PKG_REPO_LIST}\" != \"\" ]; then echo \"deb ${param_mirror} ${param_ubuntuversion} ${PKG_REPO_LIST}\" > /target/root/etc/apt/sources.list; fi && \
if [ \"${PKG_REPO_SEC_LIST}\" != \"\" ]; then echo \"deb ${param_mirror} ${param_ubuntuversion}-security ${PKG_REPO_SEC_LIST}\" >> /target/root/etc/apt/sources.list; fi && \
mount --bind dev /target/root/dev && \
mount -t proc proc /target/root/proc && \
mount -t sysfs sysfs /target/root/sys && \
LANG=C.UTF-8 chroot /target/root sh -c \
\"set -x && ${INLINE_PROXY//\'/\\\"} export TERM=xterm-color && \
export DEBIAN_FRONTEND=noninteractive && \
chmod a+rw /dev/null /dev/zero && \
mkdir -p /boot/efi && \
mount ${BOOT_PARTITION} /boot/efi && \
apt update && \
apt install -y wget ${param_kernelversion} && \
apt install -y grub-efi shim lvm2 && \
\\\$(grub-install ${BOOT_PARTITION} --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --no-nvram; exit 0) && \
update-grub && \
adduser --quiet --disabled-password --shell /bin/bash --gecos \\\"\\\" ${param_username} && \
addgroup --system admin && \
echo \\\"${param_username}:${param_password}\\\" | chpasswd && \
usermod -a -G admin ${param_username} && \
if [ -n \\\"${ubuntu_tasksel}\\\" ]; then \
apt install -y tasksel && \
tasksel install ${ubuntu_tasksel}; \
fi && \
if [ -n \\\"${ubuntu_packages}\\\" ]; then apt install -y ${ubuntu_packages}; fi && \
apt clean\"' && \
wget --header \"Authorization: token ${param_token}\" -O - ${param_bootstrapurl}/files/etc/fstab | sed -e \"s#ROOT#UUID=${rootfs_partuuid}#g\" | sed -e \"s#BOOT#UUID=${bootfs_partuuid} /boot/efi vfat umask=0077 0 1#g\" > $ROOTFS/etc/fstab" \
"${PROVISION_LOG}"
EFI_BOOT_NAME="Ubuntu ESP"
# clear all previous ESP boot entries (leftovers from previous ESP provisioning, entries named either 'Ubuntu ESP' or 'Centos ESP')
lines=$(efibootmgr | sed '/^Timeout:\|^BootCurrent:\|^BootOrder:\|^Mirror/d' | grep " ESP" | awk '{print $1}' | sed 's/^Boot//g' | sed 's/\*$//g')
for bootnum in $lines; do
run "Clearing previous EFI boot entry ${bootnum}" "efibootmgr -b ${bootnum} -B" "${PROVISION_LOG}"
done
# add EFI boot manager entry, that will jump to grub boot manager, located on boot partition
run "EFI Boot Manager" \
"efibootmgr -c -d ${DRIVE} -p 1 -L \"${EFI_BOOT_NAME}\" -l '\\EFI\\ubuntu\\grubx64.efi'" \
"${PROVISION_LOG}"
export MOUNT_DURING_INSTALL="chmod a+rw /dev/null /dev/zero && mount ${BOOT_PARTITION} /boot/efi"
else
run "Installing Ubuntu ${param_ubuntuversion} (~10 min)" \
"docker run -i --rm --privileged --name ubuntu-installer ${DOCKER_PROXY_ENV} -v $ROOTFS:/target/root ubuntu:${param_ubuntuversion} sh -c \
'if [ \"${PKG_REPO_LIST}\" != \"\" ]; then echo \"deb ${param_mirror} ${param_ubuntuversion} ${PKG_REPO_LIST}\" > /etc/apt/sources.list; fi && \
if [ \"${PKG_REPO_SEC_LIST}\" != \"\" ]; then echo \"deb ${param_mirror} ${param_ubuntuversion}-security ${PKG_REPO_SEC_LIST}\" >> /etc/apt/sources.list; fi && \
apt update && \
apt install -y debootstrap && \
debootstrap --arch ${param_arch} ${param_ubuntuversion} /target/root ${param_mirror} && \
if [ -z ${param_mirror} ]; then cp /etc/apt/sources.list /target/root/etc/apt/sources.list; fi && \
if [ \"${PKG_REPO_LIST}\" != \"\" ]; then echo \"deb ${param_mirror} ${param_ubuntuversion} ${PKG_REPO_LIST}\" > /target/root/etc/apt/sources.list; fi && \
if [ \"${PKG_REPO_SEC_LIST}\" != \"\" ]; then echo \"deb ${param_mirror} ${param_ubuntuversion}-security ${PKG_REPO_SEC_LIST}\" >> /target/root/etc/apt/sources.list; fi && \
mount --bind dev /target/root/dev && \
mount -t proc proc /target/root/proc && \
mount -t sysfs sysfs /target/root/sys && \
LANG=C.UTF-8 chroot /target/root sh -c \
\"${INLINE_PROXY//\'/\\\"} export TERM=xterm-color && \
export DEBIAN_FRONTEND=noninteractive && \
chmod a+rw /dev/null /dev/zero && \
mount ${BOOT_PARTITION} /boot && \
apt update && \
apt install -y wget ${param_kernelversion} && \
apt install -y grub-pc lvm2 && \
grub-install ${DRIVE} && \
adduser --quiet --disabled-password --shell /bin/bash --gecos \\\"\\\" ${param_username} && \
addgroup --system admin && \
echo \\\"${param_username}:${param_password}\\\" | chpasswd && \
usermod -a -G admin ${param_username} && \
if [ -n \\\"${ubuntu_tasksel}\\\" ]; then \
apt install -y tasksel && \
tasksel install ${ubuntu_tasksel}; \
fi && \
if [ -n \\\"${ubuntu_packages}\\\" ]; then apt install -y ${ubuntu_packages}; fi && \
apt clean\"' && \
wget --header \"Authorization: token ${param_token}\" -O - ${param_bootstrapurl}/files/etc/fstab | sed -e \"s#ROOT#UUID=${rootfs_partuuid}#g\" | sed -e \"s#BOOT#UUID=${bootfs_partuuid} /boot ext4 defaults 0 2#g\" > $ROOTFS/etc/fstab" \
"${PROVISION_LOG}"
export MOUNT_DURING_INSTALL="chmod a+rw /dev/null /dev/zero && mount ${BOOT_PARTITION} /boot"
fi
# shellcheck disable=SC2269 # variable origin: provision_settings_mac
node_hostname=${node_hostname}
if [ -z "${node_hostname}" ]; then
HOSTNAME="ubuntu-$(tr </dev/urandom -dc a-f0-9 | head -c10)"
else
HOSTNAME="${node_hostname}"
fi
# --- Enabling Ubuntu boostrap items ---
run "Enabling Ubuntu boostrap items" \
"wget --header \"Authorization: token ${param_token}\" -O $ROOTFS/etc/systemd/system/show-ip.service ${param_bootstrapurl}/systemd/show-ip.service && \
mkdir -p $ROOTFS/etc/systemd/system/network-online.target.wants/ && \
ln -s /etc/systemd/system/show-ip.service $ROOTFS/etc/systemd/system/network-online.target.wants/show-ip.service; \
wget --header \"Authorization: token ${param_token}\" -O - ${param_bootstrapurl}/files/etc/hosts | sed -e \"s#@@HOSTNAME@@#${HOSTNAME}#g\" > $ROOTFS/etc/hosts && \
mkdir -p $ROOTFS/etc/systemd/network/ && \
wget --header \"Authorization: token ${param_token}\" -O - ${param_bootstrapurl}/files/etc/systemd/network/wired.network > $ROOTFS/etc/systemd/network/wired.network && \
sed -i 's#^GRUB_CMDLINE_LINUX_DEFAULT=\"quiet splash\"#GRUB_CMDLINE_LINUX_DEFAULT=\"kvmgt vfio-iommu-type1 vfio-mdev i915.enable_gvt=1 kvm.ignore_msrs=1 intel_iommu=on drm.debug=0\"#' $ROOTFS/etc/default/grub && \
echo \"${HOSTNAME}\" > $ROOTFS/etc/hostname && \
echo \"LANG=en_US.UTF-8\" >> $ROOTFS/etc/default/locale && \
docker run -i --rm --privileged --name ubuntu-installer ${DOCKER_PROXY_ENV} -v $ROOTFS:/target/root ubuntu:${param_ubuntuversion} sh -c \
'mount --bind dev /target/root/dev && \
mount -t proc proc /target/root/proc && \
mount -t sysfs sysfs /target/root/sys && \
LANG=C.UTF-8 chroot /target/root sh -c \
\"${INLINE_PROXY//\'/\\\"} export TERM=xterm-color && \
export DEBIAN_FRONTEND=noninteractive && \
${MOUNT_DURING_INSTALL} && \
apt purge -y netplan.io && \
rm -rf /etc/netplan && \
systemctl enable systemd-networkd && \
update-grub && \
locale-gen --purge en_US.UTF-8 && \
dpkg-reconfigure --frontend=noninteractive locales\"'" \
"${PROVISION_LOG}"
if [ "${param_network}" == "bridged" ]; then
run "Installing the bridged network" \
"mkdir -p $ROOTFS/etc/systemd/network/ && \
wget --header \"Authorization: token ${param_token}\" -O $ROOTFS/etc/systemd/network/wired.network ${param_bootstrapurl}/files/etc/systemd/network/bridged/wired.network && \
wget --header \"Authorization: token ${param_token}\" -O $ROOTFS/etc/systemd/network/bond0.netdev ${param_bootstrapurl}/files/etc/systemd/network/bridged/bond0.netdev && \
wget --header \"Authorization: token ${param_token}\" -O $ROOTFS/etc/systemd/network/bond0.network ${param_bootstrapurl}/files/etc/systemd/network/bridged/bond0.network && \
wget --header \"Authorization: token ${param_token}\" -O $ROOTFS/etc/systemd/network/br0.netdev ${param_bootstrapurl}/files/etc/systemd/network/bridged/br0.netdev && \
wget --header \"Authorization: token ${param_token}\" -O $ROOTFS/etc/systemd/network/br0.network ${param_bootstrapurl}/files/etc/systemd/network/bridged/br0.network" \
"${PROVISION_LOG}"
elif [ "${param_network}" == "network-manager" ]; then
run "Installing Network Manager Packages on Ubuntu ${param_ubuntuversion}" \
"docker run -i --rm --privileged --name ubuntu-installer ${DOCKER_PROXY_ENV} -v /dev:/dev -v /sys/:/sys/ -v $ROOTFS:/target/root ubuntu:${param_ubuntuversion} sh -c \
'mount --bind dev /target/root/dev && \
mount -t proc proc /target/root/proc && \
mount -t sysfs sysfs /target/root/sys && \
LANG=C.UTF-8 chroot /target/root sh -c \
\"${INLINE_PROXY//\'/\\\"} export TERM=xterm-color && \
export DEBIAN_FRONTEND=noninteractive && \
apt install -y network-manager\"'" \
"${PROVISION_LOG}"
fi
if [ -d "/sys/class/ieee80211" ] && ( find /sys/class/net/wl* > /dev/null 2>&1 ); then
if [ -n "${param_wifissid}" ]; then
WIFI_NAME_ONBOARD=$(udevadm test-builtin net_id /sys/class/net/wl* 2> /dev/null | grep ID_NET_NAME_ONBOARD | awk -F'=' '{print $2}' | head -1)
WIFI_NAME_PATH=$(udevadm test-builtin net_id /sys/class/net/wl* 2> /dev/null | grep ID_NET_NAME_PATH | awk -F'=' '{print $2}' | head -1)
if [ -n "${WIFI_NAME_ONBOARD}" ]; then
WIFI_NAME=${WIFI_NAME_ONBOARD}
else
WIFI_NAME=${WIFI_NAME_PATH}
fi
if [ "${param_network}" == "bridged" ]; then
run "Installing Wifi on Ubuntu ${param_ubuntuversion}" \
"wget --header \"Authorization: token ${param_token}\" -O $ROOTFS/etc/systemd/network/wireless.network ${param_bootstrapurl}/files/etc/systemd/network/bridged/wireless.network.template && \
sed -i -e \"s#@@WIFI_NAME@@#${WIFI_NAME}#g\" $ROOTFS/etc/systemd/network/wireless.network && \
sed -i -e \"s#@@WPA_SSID@@#${param_wifissid}#g\" $ROOTFS/etc/systemd/network/wireless.network && \
sed -i -e \"s#@@WPA_PSK@@#${param_wifipsk}#g\" $ROOTFS/etc/systemd/network/wireless.network" \
"${PROVISION_LOG}"
elif [ "${param_network}" == "network-manager" ]; then
run "Installing Wifi on Ubuntu ${param_ubuntuversion}" \
"docker run -i --rm --privileged --name ubuntu-installer ${DOCKER_PROXY_ENV} -v /dev:/dev -v /sys/:/sys/ -v $ROOTFS:/target/root ubuntu:${param_ubuntuversion} sh -c \
'mount --bind dev /target/root/dev && \
mount -t proc proc /target/root/proc && \
mount -t sysfs sysfs /target/root/sys && \
LANG=C.UTF-8 chroot /target/root sh -c \
\"${INLINE_PROXY//\'/\\\"} export TERM=xterm-color && \
export DEBIAN_FRONTEND=noninteractive && \
nmcli radio wifi on && \
nmcli dev wifi connect ${param_wifissid} password '${param_wifipsk}' || true \"'" \
"${PROVISION_LOG}"
else
run "Installing Wifi on Ubuntu ${param_ubuntuversion}" \
"wget --header \"Authorization: token ${param_token}\" -O $ROOTFS/etc/systemd/network/wireless.network ${param_bootstrapurl}/files/etc/systemd/network/wireless.network.template && \
sed -i -e \"s#@@WIFI_NAME@@#${WIFI_NAME}#g\" $ROOTFS/etc/systemd/network/wireless.network && \
sed -i -e \"s#@@WPA_SSID@@#${param_wifissid}#g\" $ROOTFS/etc/systemd/network/wireless.network && \
sed -i -e \"s#@@WPA_PSK@@#${param_wifipsk}#g\" $ROOTFS/etc/systemd/network/wireless.network" \
"${PROVISION_LOG}"
fi
run "Installing Wireless Packages on Ubuntu ${param_ubuntuversion}" \
"docker run -i --rm --privileged --name ubuntu-installer ${DOCKER_PROXY_ENV} -v /dev:/dev -v /sys/:/sys/ -v $ROOTFS:/target/root ubuntu:${param_ubuntuversion} sh -c \
'mount --bind dev /target/root/dev && \
mount -t proc proc /target/root/proc && \
mount -t sysfs sysfs /target/root/sys && \
LANG=C.UTF-8 chroot /target/root sh -c \
\"${INLINE_PROXY//\'/\\\"} export TERM=xterm-color && \
export DEBIAN_FRONTEND=noninteractive && \
${MOUNT_DURING_INSTALL} && \
apt install -y wireless-tools wpasupplicant && \
mkdir -p /etc/wpa_supplicant && \
wpa_passphrase ${param_wifissid} '${param_wifipsk}' > /etc/wpa_supplicant/wpa_supplicant-${WIFI_NAME}.conf && \
systemctl enable wpa_supplicant@${WIFI_NAME}.service\"'" \
"${PROVISION_LOG}"
fi
fi
run "Enabling Kernel Modules at boot time" \
"mkdir -p $ROOTFS/etc/modules-load.d/ && \
echo 'kvmgt' > $ROOTFS/etc/modules-load.d/kvmgt.conf && \
echo 'vfio-iommu-type1' > $ROOTFS/etc/modules-load.d/vfio.conf && \
echo 'dm-crypt' > $ROOTFS/etc/modules-load.d/dm-crypt.conf && \
echo 'fuse' > $ROOTFS/etc/modules-load.d/fuse.conf && \
echo 'nbd' > $ROOTFS/etc/modules-load.d/nbd.conf && \
echo 'i915 enable_gvt=1' > $ROOTFS/etc/modules-load.d/i915.conf" \
"${PROVISION_LOG}"
if [ -f $ROOTFS/etc/skel/.bashrc ]; then
sed -i 's|#force_color_prompt=yes|force_color_prompt=yes|g' -f $ROOTFS/etc/skel/.bashrc
fi
if [ -f $ROOTFS/root/.bashrc ]; then
sed -i 's|#force_color_prompt=yes|force_color_prompt=yes|g' -f $ROOTFS/root/.bashrc
fi
if [ -f $ROOTFS/home/${param_username}/.bashrc ]; then
sed -i 's|#force_color_prompt=yes|force_color_prompt=yes|g' -f $ROOTFS/home/${param_username}/.bashrc
fi
# The proxy will be set up by Experience Kits
if [ -n "${param_proxy}" ]; then
run "Enabling Proxy Environment Variables" \
"echo -e '\
http_proxy=${param_proxy}\n\
https_proxy=${param_proxy}\n\
no_proxy=localhost,127.0.0.1' >> $ROOTFS/etc/environment" \
"${PROVISION_LOG}"
fi
if [ -n "${param_proxysocks}" ]; then
run "Enabling Socks Proxy Environment Variables" \
"echo -e 'ftp_proxy=${param_proxysocks}' >> $ROOTFS/etc/environment" \
"${PROVISION_LOG}"
fi