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