]> git.proxmox.com Git - pve-installer.git/blob - unconfigured.sh
ba9b9e33722df2d674eca9e171c0b8b322b6b0cc
[pve-installer.git] / unconfigured.sh
1 #!/bin/bash
2
3 trap "err_reboot" ERR
4
5 # NOTE: we nowadays get exec'd by the initrd's PID 1, so we're the new PID 1
6
7 parse_cmdline() {
8 proxdebug=0
9 proxtui=0
10 # shellcheck disable=SC2013 # per word splitting is wanted here
11 for par in $(cat /proc/cmdline); do
12 case $par in
13 proxdebug)
14 proxdebug=1
15 ;;
16 proxtui)
17 proxtui=1
18 ;;
19 esac
20 done;
21 }
22
23 debugsh() {
24 /bin/bash
25 }
26
27 eject_and_reboot() {
28 iso_dev=$(awk '/ iso9660 / {print $1}' /proc/mounts)
29
30 for try in 5 4 3 2 1; do
31 echo "unmounting ISO"
32 if umount -v -a --types iso9660; then
33 break
34 fi
35 if test -n $try; then
36 echo "unmount failed - trying again in 5 seconds"
37 sleep 5
38 fi
39 done
40
41 if [ -n "$iso_dev" ]; then
42 eject "$iso_dev" || true # cannot really work currently, don't care
43 fi
44
45 umount -l -n /dev
46
47 echo "rebooting - please remove the ISO boot media"
48 sleep 3
49 reboot -nf
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
53 echo b > /proc/sysrq-trigger
54 sleep 100
55 }
56
57 real_reboot() {
58 trap - ERR
59
60 if [[ -x /etc/init.d/networking ]]; then
61 /etc/init.d/networking stop
62 fi
63
64 # stop udev (release file handles)
65 /etc/init.d/udev stop
66
67 swap=$(awk '/^\/dev\// { print $1 }' /proc/swaps);
68 if [ -n "$swap" ]; then
69 echo -n "Deactivating swap..."
70 swapoff "$swap"
71 echo "done."
72 fi
73
74 # just to be sure
75 sync
76
77 umount -l -n /target >/dev/null 2>&1
78 umount -l -n /dev/pts
79 umount -l -n /dev/shm
80 umount -l -n /run
81 [ -d /sys/firmware/efi/efivars ] && umount -l -n /sys/firmware/efi/efivars
82
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
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
92
93 eject_and_reboot
94
95 exit 0 # shouldn't be reached, kernel will panic in that case
96 }
97
98 err_reboot() {
99 printf "\nInstallation aborted - unable to continue (type exit or CTRL-D to reboot)\n"
100 debugsh || true
101 real_reboot
102 }
103
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
106 handle_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
125 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin
126
127 echo "Starting Proxmox installation"
128
129 # ensure udev doesn't ignores our request; FIXME: not required anymore, as we use switch_root now
130 export SYSTEMD_IGNORE_CHROOT=1
131
132 mount -n -t proc proc /proc
133 mount -n -t sysfs sysfs /sys
134 if [ -d /sys/firmware/efi ]; then
135 echo "EFI boot mode detected, mounting efivars filesystem"
136 mount -n -t efivarfs efivarfs /sys/firmware/efi/efivars
137 fi
138 mount -n -t tmpfs tmpfs /run
139 mkdir -p /run/proxmox-installer
140
141 parse_cmdline
142
143 # always load most common input drivers
144 modprobe -q psmouse || true
145 modprobe -q sermouse || true
146 modprobe -q usbhid || true
147
148 # load device mapper - used by lilo
149 modprobe -q dm_mod || true
150
151 echo "Installing additional hardware drivers"
152 export RUNLEVEL=S
153 export PREVLEVEL=N
154 /etc/init.d/udev start
155
156 mkdir -p /dev/shm
157 mount -t tmpfs tmpfs /dev/shm
158
159 # allow pseudo terminals for debuggin in X
160 mkdir -p /dev/pts
161 mount -vt devpts devpts /dev/pts -o gid=5,mode=620
162
163 # shellcheck disable=SC2207
164 console_dim=($(IFS=' ' stty size)) # [height, width]
165 DPI=96
166 if (("${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
173 fi
174
175 # set the hostname
176 hostname proxmox
177
178 if 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
186 fi
187
188 # we use a trimmed down debootstrap so make busybox tools available to compensate that
189 busybox --install -s || true
190
191 setupcon || echo "setupcon failed, TUI rendering might be garbled - $?"
192
193 if [ $proxdebug -ne 0 ]; then
194 /sbin/agetty -o '-p -- \\u' --noclear tty9 &
195 printf "\nDropping in debug shell before starting installation\n"
196 echo "type 'exit' or press CTRL + D to continue and start the installation wizard"
197 debugsh || true
198 fi
199
200 # try to get ip config with dhcp
201 echo -n "Attempting to get DHCP leases... "
202 dhclient -v
203 echo "done"
204
205 echo "Starting chrony for opportunistic time-sync... "
206 chronyd || echo "starting chrony failed ($?)"
207
208 echo "Starting a root shell on tty3."
209 setsid /sbin/agetty -a root --noclear tty3 &
210
211 /usr/bin/proxmox-low-level-installer dump-env
212
213 if [ $proxtui -ne 0 ]; then
214 echo "Starting the TUI installer"
215 /usr/bin/proxmox-tui-installer 2>/dev/tty2
216 else
217 echo "Starting the installer GUI - see tty2 (CTRL+ALT+F2) for any errors..."
218 xinit -- -dpi "$DPI" >/dev/tty2 2>&1
219 fi
220
221 # just to be sure everything is on disk
222 sync
223
224 if [ $proxdebug -ne 0 ]; then
225 printf "\nDebug shell after installation exited (type exit or CTRL-D to reboot)\n"
226 debugsh || true
227 fi
228
229 echo "Installation done, rebooting... "
230
231 killall5 -15
232
233 real_reboot
234
235 # never reached
236 exit 0