]> git.draconx.ca Git - scripts.git/blob - init-kexec.sh
Add script to convert "JWK"-format RSA keys to normal.
[scripts.git] / init-kexec.sh
1 #!/bin/sh
2 #
3 # Copyright © 2014 Nick Bowler
4 #
5 # Very simple kexec-based "bootloader", intended to be run as init.  Allows
6 # the user to select one of a list of kernels, or boot a default if no user
7 # action is given within the timeout.
8 #
9 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
10 # This is free software: you are free to do what the fuck you want to.
11 # There is NO WARRANTY, to the extent permitted by law.
12
13 default=vmlinuz
14 cmdline='root=/dev/vda init=/sbin/init.sysv'
15 timeout=10
16 width=60
17
18 do_dialog() {
19         dmesg --console-off >/dev/null 2>&1
20         exec 3>&1
21         eval_result=`printf 'dialog_output='
22                      command dialog --keep-tite --quoted "$@" 2>&1 1>&3
23                      printf '\ndialog_status=%d\n' $?`
24         exec 3>&-
25         dmesg --console-on >/dev/null 2>&1
26         eval "$eval_result" && (exit $dialog_status)
27 }
28
29 do_shell() {
30         printf 'Cancelled; dropping to shell\n' 1>&2
31         
32         test "$$" = 1 && exec /bin/sh
33         exit 1
34 }
35
36 if do_dialog --defaultno --ok-label Skip --pause \
37         'Booting default (Ctrl+C to interrupt)...' 8 $width $timeout
38 then
39         kernel=$default
40 else
41         do_dialog --no-tags --default-item "$default" --menu \
42                 'Select kernel to boot, or cancel to exit to shell.' \
43                 20 $width 20 \
44                 'vmlinuz.old' 'vmlinuz.old' \
45                 'vmlinuz' 'vmlinuz' || do_shell
46         kernel=$dialog_output
47 fi
48
49 printf 'Selected %s\n' "$kernel"
50
51 kexec -l "/boot/$kernel" --command-line="$cmdline" || do_shell
52 if test "$$" = 1; then
53         # Only execute new kernel if we are init.
54         kexec -e
55 fi
56
57 # Failing that, drop to shell.
58 do_shell