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