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