]> git.proxmox.com Git - pve-installer.git/blame - unconfigured.sh
install module: getters: correctly use plural in error messages
[pve-installer.git] / unconfigured.sh
CommitLineData
89a12446
DM
1#!/bin/bash
2
3trap "err_reboot" ERR
4
0acbbbf5
TL
5# NOTE: we nowadays get exec'd by the initrd's PID 1, so we're the new PID 1
6
89a12446 7parse_cmdline() {
135f5269 8 start_auto_installer=0
89a12446 9 proxdebug=0
7a11b298 10 proxtui=0
e2cbcc4e 11 serial=0
9e5787e5 12 # shellcheck disable=SC2013 # per word splitting is wanted here
dbe9a0c9 13 for par in $(cat /proc/cmdline); do
9e5787e5 14 case $par in
de7f779d 15 proxdebug|proxmox-debug)
7a11b298
TL
16 proxdebug=1
17 ;;
de7f779d 18 proxtui|proxmox-tui-mode)
7a11b298 19 proxtui=1
9e5787e5 20 ;;
de7f779d 21 proxauto|proxmox-start-auto-installer)
135f5269 22 start_auto_installer=1
327506cc 23 ;;
a31259b1
SI
24 console=ttyS*)
25 serial=1
26 ;;
9e5787e5 27 esac
89a12446
DM
28 done;
29}
30
31debugsh() {
16ff00ec 32 /bin/bash
89a12446
DM
33}
34
0acbbbf5
TL
35eject_and_reboot() {
36 iso_dev=$(awk '/ iso9660 / {print $1}' /proc/mounts)
37
38 for try in 5 4 3 2 1; do
298bdcaf
TL
39 echo "unmounting ISO"
40 if umount -v -a --types iso9660; then
0acbbbf5
TL
41 break
42 fi
43 if test -n $try; then
e13e3510 44 echo "unmount failed - trying again in 5 seconds"
0acbbbf5
TL
45 sleep 5
46 fi
47 done
48
49 if [ -n "$iso_dev" ]; then
6ce4f3d7 50 eject "$iso_dev" || true # cannot really work currently, don't care
0acbbbf5
TL
51 fi
52
cd801ab8
TL
53 umount -l -n /dev
54
0acbbbf5
TL
55 echo "rebooting - please remove the ISO boot media"
56 sleep 3
024449f1 57 reboot -nf
6ce4f3d7
TL
58 sleep 5
59 echo "trigger reset system request"
60 # we do not expect the reboot above to fail, so rather to avoid kpanic when pid 1 exits
0acbbbf5
TL
61 echo b > /proc/sysrq-trigger
62 sleep 100
63}
64
89a12446 65real_reboot() {
dbe9a0c9 66 trap - ERR
89a12446 67
e13e3510
TL
68 if [[ -x /etc/init.d/networking ]]; then
69 /etc/init.d/networking stop
70 fi
89a12446
DM
71
72 # stop udev (release file handles)
73 /etc/init.d/udev stop
74
20d20ee3 75 swap=$(awk '/^\/dev\// { print $1 }' /proc/swaps);
89a12446 76 if [ -n "$swap" ]; then
6856f73c
TL
77 echo -n "Deactivating swap..."
78 swapoff "$swap"
79 echo "done."
89a12446 80 fi
89a12446 81
6ce4f3d7
TL
82 # just to be sure
83 sync
84
89a12446 85 umount -l -n /target >/dev/null 2>&1
57a8f6e5
TL
86 umount -l -n /dev/pts
87 umount -l -n /dev/shm
8d7ddbde 88 umount -l -n /run
dea730ea 89 [ -d /sys/firmware/efi/efivars ] && umount -l -n /sys/firmware/efi/efivars
89a12446 90
0acbbbf5
TL
91 # do not unmount proc and sys for now, at least /proc is still required to trigger the actual
92 # reboot, and both are virtual FS only anyway
93
8a13026d
TL
94 echo "Terminate all remaining processes"
95 kill -s TERM -1 # TERMinate all but current init (our self) PID 1
96 sleep 2
97 echo "Kill any remaining processes"
98 kill -s KILL -1 # KILL all but current init (our self) PID 1
99 sleep 0.5
0acbbbf5
TL
100
101 eject_and_reboot
102
103 exit 0 # shouldn't be reached, kernel will panic in that case
89a12446
DM
104}
105
126379f6
CH
106# reachable through the ERR trap
107# shellcheck disable=SC2317
89a12446 108err_reboot() {
4fb3a9c6 109 printf "\nInstallation aborted - unable to continue (type exit or CTRL-D to reboot)\n"
2e3fe722 110 debugsh || true
89a12446
DM
111 real_reboot
112}
113
478b111c
TL
114# NOTE: dbus must be launched before this, else iwd cannot work
115# FIXME: very crude, still needs to actually copy over any iwd config to target
116handle_wireless() {
117 wireless_found=
118 for iface in /sys/class/net/*; do
119 if [ -d "$iface/wireless" ]; then
120 wireless_found=1
121 fi
122 done
123 if [ -z $wireless_found ]; then
124 return;
125 fi
126
127 if [ -x /usr/libexec/iwd ]; then
128 echo "wireless device(s) found, starting iwd; use 'iwctl' to manage connections (experimental)"
129 /usr/libexec/iwd &
130 else
131 echo "wireless device found but iwd not available, ignoring"
132 fi
133}
134
89a12446
DM
135PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin
136
fff4bc47
TL
137echo "Starting Proxmox installation"
138
0acbbbf5 139# ensure udev doesn't ignores our request; FIXME: not required anymore, as we use switch_root now
194d737a
TL
140export SYSTEMD_IGNORE_CHROOT=1
141
89a12446 142mount -n -t proc proc /proc
89a12446 143mount -n -t sysfs sysfs /sys
f238dd03
TL
144if [ -d /sys/firmware/efi ]; then
145 echo "EFI boot mode detected, mounting efivars filesystem"
dea730ea 146 mount -n -t efivarfs efivarfs /sys/firmware/efi/efivars
f238dd03 147fi
8d7ddbde 148mount -n -t tmpfs tmpfs /run
de629a23 149mkdir -p /run/proxmox-installer
89a12446
DM
150
151parse_cmdline
152
153# always load most common input drivers
000f289d
TL
154modprobe -q psmouse || true
155modprobe -q sermouse || true
156modprobe -q usbhid || true
89a12446
DM
157
158# load device mapper - used by lilo
000f289d 159modprobe -q dm_mod || true
89a12446
DM
160
161echo "Installing additional hardware drivers"
dbe9a0c9 162export RUNLEVEL=S
89a12446
DM
163export PREVLEVEL=N
164/etc/init.d/udev start
165
3119bdeb
TL
166mkdir -p /dev/shm
167mount -t tmpfs tmpfs /dev/shm
168
4569e022
TL
169# allow pseudo terminals for debuggin in X
170mkdir -p /dev/pts
171mount -vt devpts devpts /dev/pts -o gid=5,mode=620
172
cbddb92d
TL
173# shellcheck disable=SC2207
174console_dim=($(IFS=' ' stty size)) # [height, width]
175DPI=96
176if (("${console_dim[0]}" > 100)) && (("${console_dim[1]}" > 400)); then
177 # heuristic only, high resolution can still mean normal/low DPI if it's a really big screen
178 # FIXME: use `edid-decode` as it can contain physical dimensions to calculate actual dpi?
179 echo "detected huge console, setting bigger font/dpi"
180 DPI=192
181 export GDK_SCALE=2
182 setfont /usr/share/consolefonts/Uni2-Terminus32x16.psf.gz
183fi
184
d5268f68
TL
185# set the hostname
186hostname proxmox
187
478b111c
TL
188if command -v dbus-daemon; then
189 echo "starting D-Bus daemon"
190 mkdir /run/dbus
191 dbus-daemon --system --syslog-only
192
193 if [ $proxdebug -ne 0 ]; then # FIXME: better intergration, e.g., use iwgtk?
194 handle_wireless # no-op if not wireless dev is found
195 fi
196fi
197
291ac3b6
TL
198# we use a trimmed down debootstrap so make busybox tools available to compensate that
199busybox --install -s || true
200
521662f8
TL
201setupcon || echo "setupcon failed, TUI rendering might be garbled - $?"
202
3facbe51
CH
203if [ "$serial" -ne 0 ]; then
204 echo "Setting terminal size to 80x24 for serial install"
205 stty columns 80 rows 24
206fi
207
11a42156 208if [ $proxdebug -ne 0 ]; then
aa0fe276 209 /sbin/agetty -o '-p -- \\u' --noclear tty9 &
fff4bc47 210 printf "\nDropping in debug shell before starting installation\n"
521662f8 211 echo "type 'exit' or press CTRL + D to continue and start the installation wizard"
2e3fe722 212 debugsh || true
11a42156
TL
213fi
214
1ca401af 215# add custom DHCP options for auto installer
135f5269 216if [ $start_auto_installer -ne 0 ]; then
a101adee 217 echo "Preparing DHCP as potential source to get location of automatic-installation answer file"
1ca401af 218 cat >> /etc/dhcp/dhclient.conf <<EOF
a101adee
TL
219option proxmox-auto-installer-manifest-url code 250 = text;
220option proxmox-auto-installer-cert-fingerprint code 251 = text;
221also request proxmox-auto-installer-manifest-url, proxmox-auto-installer-cert-fingerprint;
1ca401af
AL
222EOF
223fi
224
89a12446 225# try to get ip config with dhcp
01e402f0
FG
226echo -n "Attempting to get DHCP leases... "
227dhclient -v
89a12446
DM
228echo "done"
229
203059a9 230echo "Starting chrony for opportunistic time-sync... "
d5268f68 231chronyd || echo "starting chrony failed ($?)"
150291b3 232
909936b5
SI
233echo "Starting a root shell on tty3."
234setsid /sbin/agetty -a root --noclear tty3 &
235
de629a23
TL
236/usr/bin/proxmox-low-level-installer dump-env
237
7a11b298
TL
238if [ $proxtui -ne 0 ]; then
239 echo "Starting the TUI installer"
65694938 240 /usr/bin/proxmox-tui-installer 2>/dev/tty2
135f5269 241elif [ $start_auto_installer -ne 0 ]; then
795ca4bc 242 echo "Caching device info from udev"
327506cc 243 /usr/bin/proxmox-low-level-installer dump-udev
1530128b
TL
244
245 if [ -f /cdrom/auto-installer-mode.toml ]; then
246 echo "Fetching answers for automatic installation"
247 /usr/bin/proxmox-fetch-answer >/run/automatic-installer-answers
248 else
249 printf "\nAutomatic installation selected but no config for fetching the answer file found!\n"
250 echo "Starting debug shell, to fetch the answer file manually use:"
251 echo " proxmox-fetch-answer MODE >/run/automatic-installer-answers"
252 echo "and enter 'exit' or press 'CTRL' + 'D' when finished."
253 debugsh || true
254 fi
327506cc 255 echo "Starting automatic installation"
795ca4bc 256 /usr/bin/proxmox-auto-installer </run/automatic-installer-answers
7a11b298
TL
257else
258 echo "Starting the installer GUI - see tty2 (CTRL+ALT+F2) for any errors..."
0d97286c 259 xinit -- -dpi "$DPI" -s 0 >/dev/tty2 2>&1
7a11b298 260fi
89a12446 261
b0c4afcc
DM
262# just to be sure everything is on disk
263sync
264
89a12446 265if [ $proxdebug -ne 0 ]; then
fff4bc47 266 printf "\nDebug shell after installation exited (type exit or CTRL-D to reboot)\n"
2e3fe722 267 debugsh || true
89a12446
DM
268fi
269
270echo "Installation done, rebooting... "
d13c1966
TL
271
272killall5 -15
273
89a12446
DM
274real_reboot
275
276# never reached
126379f6 277# shellcheck disable=SC2317
89a12446 278exit 0