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