-
Notifications
You must be signed in to change notification settings - Fork 26
/
unconfigured.sh
executable file
·285 lines (231 loc) · 7.97 KB
/
unconfigured.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
273
274
275
276
277
278
279
280
281
282
283
284
285
#!/bin/bash
trap "err_reboot" ERR
# NOTE: we nowadays get exec'd by the initrd's PID 1, so we're the new PID 1
parse_cmdline() {
start_auto_installer=0
proxdebug=0
proxtui=0
serial=0
# shellcheck disable=SC2013 # per word splitting is wanted here
for par in $(cat /proc/cmdline); do
case $par in
proxdebug|proxmox-debug)
proxdebug=1
;;
proxtui|proxmox-tui-mode)
proxtui=1
;;
proxauto|proxmox-start-auto-installer)
start_auto_installer=1
;;
console=ttyS*)
serial=1
;;
esac
done;
}
debugsh() {
/bin/bash
}
eject_and_reboot() {
iso_dev=$(awk '/ iso9660 / {print $1}' /proc/mounts)
for try in 5 4 3 2 1; do
echo "unmounting ISO"
if umount -v -a --types iso9660; then
break
fi
if test -n $try; then
echo "unmount failed - trying again in 5 seconds"
sleep 5
fi
done
if [ -n "$iso_dev" ]; then
eject "$iso_dev" || true # cannot really work currently, don't care
fi
umount -l -n /dev
echo "rebooting - please remove the ISO boot media"
sleep 3
reboot -nf
sleep 5
echo "trigger reset system request"
# we do not expect the reboot above to fail, so rather to avoid kpanic when pid 1 exits
echo b > /proc/sysrq-trigger
sleep 100
}
real_reboot() {
trap - ERR
if [[ -x /etc/init.d/networking ]]; then
/etc/init.d/networking stop
fi
# stop udev (release file handles)
/etc/init.d/udev stop
swap=$(awk '/^\/dev\// { print $1 }' /proc/swaps);
if [ -n "$swap" ]; then
echo -n "Deactivating swap..."
swapoff "$swap"
echo "done."
fi
# just to be sure
sync
umount -l -n /target >/dev/null 2>&1
umount -l -n /dev/pts
umount -l -n /dev/shm
umount -l -n /run
[ -d /sys/firmware/efi/efivars ] && umount -l -n /sys/firmware/efi/efivars
# do not unmount proc and sys for now, at least /proc is still required to trigger the actual
# reboot, and both are virtual FS only anyway
echo "Terminate all remaining processes"
kill -s TERM -1 # TERMinate all but current init (our self) PID 1
sleep 2
echo "Kill any remaining processes"
kill -s KILL -1 # KILL all but current init (our self) PID 1
sleep 0.5
eject_and_reboot
exit 0 # shouldn't be reached, kernel will panic in that case
}
# reachable through the ERR trap
# shellcheck disable=SC2317
err_reboot() {
printf "\nInstallation aborted - unable to continue (type exit or CTRL-D to reboot)\n"
debugsh || true
real_reboot
}
# NOTE: dbus must be launched before this, else iwd cannot work
# FIXME: very crude, still needs to actually copy over any iwd config to target
handle_wireless() {
wireless_found=
for iface in /sys/class/net/*; do
if [ -d "$iface/wireless" ]; then
wireless_found=1
fi
done
if [ -z $wireless_found ]; then
return;
fi
if [ -x /usr/libexec/iwd ]; then
echo "wireless device(s) found, starting iwd; use 'iwctl' to manage connections (experimental)"
/usr/libexec/iwd &
else
echo "wireless device found but iwd not available, ignoring"
fi
}
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin
echo "Starting Proxmox installation"
# ensure udev doesn't ignores our request; FIXME: not required anymore, as we use switch_root now
export SYSTEMD_IGNORE_CHROOT=1
mount -n -t proc proc /proc
mount -n -t sysfs sysfs /sys
if [ -d /sys/firmware/efi ]; then
echo "EFI boot mode detected, mounting efivars filesystem"
mount -n -t efivarfs efivarfs /sys/firmware/efi/efivars
fi
mount -n -t tmpfs tmpfs /run
mkdir -p /run/proxmox-installer
parse_cmdline
# always load most common input drivers
modprobe -q psmouse || true
modprobe -q sermouse || true
modprobe -q usbhid || true
# load device mapper - used by lilo
modprobe -q dm_mod || true
echo "Installing additional hardware drivers"
export RUNLEVEL=S
export PREVLEVEL=N
/etc/init.d/udev start
mkdir -p /dev/shm
mount -t tmpfs tmpfs /dev/shm
# allow pseudo terminals for debugging in X
mkdir -p /dev/pts
mount -vt devpts devpts /dev/pts -o gid=5,mode=620
# shellcheck disable=SC2207
console_dim=($(IFS=' ' stty size)) # [height, width]
DPI=96
if (("${console_dim[0]}" > 100)) && (("${console_dim[1]}" > 400)); then
# heuristic only, high resolution can still mean normal/low DPI if it's a really big screen
# FIXME: use `edid-decode` as it can contain physical dimensions to calculate actual dpi?
echo "detected huge console, setting bigger font/dpi"
DPI=192
export GDK_SCALE=2
setfont /usr/share/consolefonts/Uni2-Terminus32x16.psf.gz
fi
# set the hostname
hostname proxmox
if command -v dbus-daemon; then
echo "starting D-Bus daemon"
mkdir /run/dbus
dbus-daemon --system --syslog-only
if [ $proxdebug -ne 0 ]; then # FIXME: better integration, e.g., use iwgtk?
handle_wireless # no-op if not wireless dev is found
fi
fi
# we use a trimmed down debootstrap so make busybox tools available to compensate that
busybox --install -s || true
setupcon || echo "setupcon failed, TUI rendering might be garbled - $?"
if [ "$serial" -ne 0 ]; then
echo "Setting terminal size to 80x24 for serial install"
stty columns 80 rows 24
fi
if [ $proxdebug -ne 0 ]; then
/sbin/agetty -o '-p -- \\u' --noclear tty9 &
printf "\nDropping in debug shell before starting installation\n"
echo "type 'exit' or press CTRL + D to continue and start the installation wizard"
debugsh || true
fi
# add custom DHCP options for auto installer
if [ $start_auto_installer -ne 0 ]; then
echo "Preparing DHCP as potential source to get location of automatic-installation answer file"
cat >> /etc/dhcp/dhclient.conf <<EOF
option proxmox-auto-installer-manifest-url code 250 = text;
option proxmox-auto-installer-cert-fingerprint code 251 = text;
also request proxmox-auto-installer-manifest-url, proxmox-auto-installer-cert-fingerprint;
EOF
fi
# try to get ip config with dhcp
echo -n "Attempting to get DHCP leases... "
dhclient -v
echo "done"
echo "Starting chrony for opportunistic time-sync... "
chronyd || echo "starting chrony failed ($?)"
echo "Starting a root shell on tty3."
setsid /sbin/agetty -a root --noclear tty3 &
/usr/bin/proxmox-low-level-installer dump-env
if [ $proxtui -ne 0 ]; then
echo "Starting the TUI installer"
/usr/bin/proxmox-tui-installer 2>/dev/tty2
elif [ $start_auto_installer -ne 0 ]; then
echo "Caching device info from udev"
/usr/bin/proxmox-low-level-installer dump-udev
if [ -f /cdrom/auto-installer-mode.toml ]; then
echo "Fetching answers for automatic installation"
/usr/bin/proxmox-fetch-answer >/run/automatic-installer-answers
else
printf "\nAutomatic installation selected but no config for fetching the answer file found!\n"
echo "Starting debug shell, to fetch the answer file manually use:"
echo " proxmox-fetch-answer MODE >/run/automatic-installer-answers"
echo "and enter 'exit' or press 'CTRL' + 'D' when finished."
debugsh || true
fi
echo "Starting automatic installation"
if /usr/bin/proxmox-auto-installer </run/automatic-installer-answers; then
if ! /usr/bin/proxmox-post-hook </run/automatic-installer-answers; then
echo "post installation hook failed to execute."
echo "waiting 30s to allow gathering the error before reboot."
sleep 30
fi
fi
else
echo "Starting the installer GUI - see tty2 (CTRL+ALT+F2) for any errors..."
xinit -- -dpi "$DPI" -s 0 >/dev/tty2 2>&1
fi
# just to be sure everything is on disk
sync
if [ $proxdebug -ne 0 ]; then
printf "\nDebug shell after installation exited (type exit or CTRL-D to reboot)\n"
debugsh || true
fi
echo "Installation done, rebooting... "
killall5 -15
real_reboot
# never reached
# shellcheck disable=SC2317
exit 0