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