diff options
Diffstat (limited to 'old-school/menu-select')
-rwxr-xr-x | old-school/menu-select | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/old-school/menu-select b/old-school/menu-select new file mode 100755 index 0000000..0cc0c67 --- /dev/null +++ b/old-school/menu-select | |||
@@ -0,0 +1,112 @@ | |||
1 | #!/bin/sh | ||
2 | # usage: | ||
3 | # $0 boot-ram - use memory-only overlay | ||
4 | # $0 boot-new [dev name] [loop file] [megabytes] - create new luks-encrypted overlay | ||
5 | # $0 boot-overwrite [dev name] [loop file] [megabytes] - overwrite with new luks overlay | ||
6 | # $0 boot-luks [dev name] [loop file] - boot existing luks-encrypted overlay | ||
7 | # $0 boot-gpg [key id] [gnupg homedir] [???] - boot any device signed with the key | ||
8 | |||
9 | . lvm-create.sh | ||
10 | . common.sh | ||
11 | exec 4>&1 | ||
12 | debug_log | ||
13 | |||
14 | error() | ||
15 | { | ||
16 | local sleep=3 | ||
17 | |||
18 | clear >&4 | ||
19 | echo "error -- ${*:-:(}" >&4 | ||
20 | |||
21 | if [ $sleep -gt 0 ]; then | ||
22 | echo "will try again in $sleep seconds..." >&4 | ||
23 | sleep $sleep | ||
24 | fi | ||
25 | bootmenu do_trigger no_panic | ||
26 | exit | ||
27 | } | ||
28 | |||
29 | badopts= | ||
30 | fs= | ||
31 | while [ $# -ge 1 ]; do | ||
32 | case $1 in | ||
33 | --fs=*) fs="${1#--fs=}"; shift; continue ;; | ||
34 | --*) echo "error: unknown option $1"; badopts=true; shift; continue ;; | ||
35 | esac | ||
36 | break | ||
37 | done | ||
38 | [ -z "$badopts" ] || error 'usage error' | ||
39 | |||
40 | [ $# -ge 2 -o "$1" = 'boot-ram' ] || error 'usage error' | ||
41 | |||
42 | remountrw() | ||
43 | { | ||
44 | local fs="$1" dev="$2" loopfile="$3" | ||
45 | if [ "$fs" = hfsplus ]; then | ||
46 | mountpoint="/mnt/${dev##*/}" | ||
47 | umount "$dev" || error | ||
48 | fsck.hfsplus -q "$dev" || error | ||
49 | mount -o force "$dev" "$mountpoint" || error | ||
50 | else | ||
51 | mount -o remount,rw "$dev" || error | ||
52 | fi | ||
53 | } | ||
54 | |||
55 | hwclock_to_system() | ||
56 | { | ||
57 | local fs="$1" UTC=UTC | ||
58 | case "$fs" in ntfs|vfat) UTC=LOCAL ;; esac | ||
59 | printf '0.0 0 0.0\n0\n%s' $UTC > /etc/adjtime | ||
60 | hwclock --hctosys | ||
61 | } | ||
62 | |||
63 | case "$1" in | ||
64 | boot-ram) | ||
65 | modprobe squashfs || true | ||
66 | find_squashfs_root | mountsquashes || error | ||
67 | mkdir /overlay || error | ||
68 | mount -t tmpfs tmpfs /overlay || error | ||
69 | mkdir /overlay/gpg || error | ||
70 | ln -s /overlay/gpg /gpg | ||
71 | |||
72 | init_gpg || error | ||
73 | bootdone squashfs-root rw-overlay | ||
74 | ;; | ||
75 | boot-overwrite|boot-new|boot-luks) | ||
76 | dev="$2" | ||
77 | loopfile="$3" | ||
78 | megs="$4" | ||
79 | |||
80 | [ "$1" != 'boot-new' -o ! -e "$loopfile" ] || error | ||
81 | |||
82 | remountrw "$fs" "$dev" "$loopfile" || error | ||
83 | |||
84 | hwclock_to_system "$fs" | ||
85 | |||
86 | if [ "$1" = 'boot-overwrite' ]; then | ||
87 | rm "$loopfile" "$loopfile"k | ||
88 | fi | ||
89 | |||
90 | init_gpg || error | ||
91 | |||
92 | if [ "$1" = 'boot-luks' ]; then | ||
93 | open_samizdat "$loopfile" "$loopfile"k || error | ||
94 | exit | ||
95 | fi | ||
96 | |||
97 | start_meter "Allocating ${megs}MB in '$loopfile' on $dev..." | ||
98 | |||
99 | if init_samizdat "$loopfile" "$megs" "$loopfile"k; then | ||
100 | stop_meter done. | ||
101 | else | ||
102 | stop_meter error! | ||
103 | rm "$loopfile" "$loopfile"k | ||
104 | error | ||
105 | fi | ||
106 | ;; | ||
107 | *) | ||
108 | error "Unimplemented boot command: $*" | ||
109 | ;; | ||
110 | esac | ||
111 | |||
112 | # vim:ts=2 sw=2 et | ||