]> git.proxmox.com Git - pve-installer.git/blob - unconfigured.sh
unconfigured: add some more newline to log messages
[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 # shellcheck disable=SC2013 # per word splitting is wanted here
10 for par in $(cat /proc/cmdline); do
11 case $par in
12 proxdebug)
13 proxdebug=1
14 ;;
15 esac
16 done;
17 }
18
19 debugsh() {
20 /bin/bash
21 }
22
23 eject_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
32 echo "unmount failed -trying again in 5 seconds"
33 sleep 5
34 fi
35 done
36
37 if [ -n "$iso_dev" ]; then
38 eject "$iso_dev"
39 fi
40
41 echo "rebooting - please remove the ISO boot media"
42 sleep 3
43 echo b > /proc/sysrq-trigger
44 sleep 100
45 }
46
47 real_reboot() {
48 trap - ERR
49
50 /etc/init.d/networking stop
51
52 # stop udev (release file handles)
53 /etc/init.d/udev stop
54
55 echo -n "Deactivating swap..."
56 swap=$(awk '/^\/dev\// { print $1 }' /proc/swaps);
57 if [ -n "$swap" ]; then
58 swapoff "$swap"
59 fi
60 echo "done."
61
62 umount -l -n /target >/dev/null 2>&1
63 umount -l -n /dev/pts
64 umount -l -n /dev/shm
65 umount -l -n /dev
66 umount -l -n /run
67 [ -d /sys/firmware/efi/efivars ] && umount -l -n /sys/firmware/efi/efivars
68
69 # do not unmount proc and sys for now, at least /proc is still required to trigger the actual
70 # reboot, and both are virtual FS only anyway
71
72 kill -s KILL -1 # kill all but current init (our self) PID 1
73 sleep 1
74
75 eject_and_reboot
76
77 exit 0 # shouldn't be reached, kernel will panic in that case
78 }
79
80 err_reboot() {
81 printf "\nInstallation aborted - unable to continue (type exit or CTRL-D to reboot)\n"
82 debugsh || true
83 real_reboot
84 }
85
86 # NOTE: dbus must be launched before this, else iwd cannot work
87 # FIXME: very crude, still needs to actually copy over any iwd config to target
88 handle_wireless() {
89 wireless_found=
90 for iface in /sys/class/net/*; do
91 if [ -d "$iface/wireless" ]; then
92 wireless_found=1
93 fi
94 done
95 if [ -z $wireless_found ]; then
96 return;
97 fi
98
99 if [ -x /usr/libexec/iwd ]; then
100 echo "wireless device(s) found, starting iwd; use 'iwctl' to manage connections (experimental)"
101 /usr/libexec/iwd &
102 else
103 echo "wireless device found but iwd not available, ignoring"
104 fi
105 }
106
107 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin
108
109 echo "Starting Proxmox installation"
110
111 # ensure udev doesn't ignores our request; FIXME: not required anymore, as we use switch_root now
112 export SYSTEMD_IGNORE_CHROOT=1
113
114 mount -n -t proc proc /proc
115 mount -n -t sysfs sysfs /sys
116 if [ -d /sys/firmware/efi ]; then
117 echo "EFI boot mode detected, mounting efivars filesystem"
118 mount -n -t efivarfs efivarfs /sys/firmware/efi/efivars
119 fi
120 mount -n -t tmpfs tmpfs /run
121
122 parse_cmdline
123
124 # always load most common input drivers
125 modprobe -q psmouse || true
126 modprobe -q sermouse || true
127 modprobe -q usbhid || true
128
129 # load device mapper - used by lilo
130 modprobe -q dm_mod || true
131
132 echo "Installing additional hardware drivers"
133 export RUNLEVEL=S
134 export PREVLEVEL=N
135 /etc/init.d/udev start
136
137 mkdir -p /dev/shm
138 mount -t tmpfs tmpfs /dev/shm
139
140 # allow pseudo terminals for debuggin in X
141 mkdir -p /dev/pts
142 mount -vt devpts devpts /dev/pts -o gid=5,mode=620
143
144 # set the hostname
145 hostname proxmox
146
147 if command -v dbus-daemon; then
148 echo "starting D-Bus daemon"
149 mkdir /run/dbus
150 dbus-daemon --system --syslog-only
151
152 if [ $proxdebug -ne 0 ]; then # FIXME: better intergration, e.g., use iwgtk?
153 handle_wireless # no-op if not wireless dev is found
154 fi
155 fi
156
157 if [ $proxdebug -ne 0 ]; then
158 /sbin/agetty -o '-p -- \\u' --noclear tty9 &
159 printf "\nDropping in debug shell before starting installation\n"
160 echo "type exit or CTRL-D to continue and start the installation wizard"
161 debugsh || true
162 fi
163
164 # try to get ip config with dhcp
165 echo -n "Attempting to get DHCP leases... "
166 dhclient -v
167 echo "done"
168
169 echo -n "Starting chrony for opportunistic time-sync... "
170 chronyd || echo "starting chrony failed ($?)"
171
172 echo "Starting a root shell on tty3."
173 setsid /sbin/agetty -a root --noclear tty3 &
174
175 xinit -- -dpi 96 >/dev/tty2 2>&1
176
177 # just to be sure everything is on disk
178 sync
179
180 if [ $proxdebug -ne 0 ]; then
181 printf "\nDebug shell after installation exited (type exit or CTRL-D to reboot)\n"
182 debugsh || true
183 fi
184
185 echo "Installation done, rebooting... "
186
187 killall5 -15
188
189 real_reboot
190
191 # never reached
192 exit 0