diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/xorriso-usb.sh | 138 |
1 files changed, 69 insertions, 69 deletions
diff --git a/src/xorriso-usb.sh b/src/xorriso-usb.sh index 511ba0e..a42764b 100644 --- a/src/xorriso-usb.sh +++ b/src/xorriso-usb.sh | |||
@@ -1,66 +1,5 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | . samizdat-paths.sh || exit 1 | ||
4 | |||
5 | outdev= | ||
6 | volid=SamizdatLive | ||
7 | gpg_iso_path=gnupghome | ||
8 | gnupghome= | ||
9 | child_dir=$samizdat_child_dir/child.$$ | ||
10 | vmlinuz_dir=$samizdat_linux_dir | ||
11 | efi_dir=$samizdat_grub_efi_dir | ||
12 | |||
13 | die() { printf "%s: Error: %s\n" "$0" "$*" >&2; exit 1; } | ||
14 | |||
15 | TEMP="$(getopt -o '' --long bootloader,reuse-child:,adam,usb,detach,in:,out:,test -n "$0" -- "$@")" || | ||
16 | die 'getopt error' | ||
17 | eval set -- "$TEMP" | ||
18 | |||
19 | ADAM=; DETACH=; USB=y | ||
20 | while [ $# -gt 0 ]; do | ||
21 | case "$1" in | ||
22 | --adam) shift; ADAM=y;; | ||
23 | --bootloader) shift; BOOTLOADER_ONLY=y;; | ||
24 | --cdrom) shift; USB=;; | ||
25 | --detach) shift; DETACH=y;; | ||
26 | --test) shift; QUICK_TEST=y;; | ||
27 | --out) CMDLINE_OUTDEV="$2"; USB=; shift 2;; | ||
28 | --in) INPUT_DEVICE="$2"; shift 2;; | ||
29 | --reuse-child) REUSE_CHILD=y; child_dir=$samizdat_child_dir/child."$2"; shift 2;; | ||
30 | --) shift; break;; | ||
31 | *) die 'getopt error';; | ||
32 | esac | ||
33 | done | ||
34 | |||
35 | if [ "$INPUT_DEVICE" ]; then | ||
36 | die "support for --in is disabled because xorriso needs different arguments to produce a bootable image" | ||
37 | |||
38 | elif [ $# = 0 -a -z "$BOOTLOADER_ONLY" ]; then | ||
39 | if mountpoint -q /cdrom; then | ||
40 | INPUT_DEVICE=/cdrom | ||
41 | elif [ -e debian-live-8.4.0-amd64-standard.btrfs -a -e layer.btrfs ]; then | ||
42 | set -- debian-live-8.4.0-amd64-standard.btrfs layer.btrfs | ||
43 | elif [ -e /srv/nbd.btrfs ]; then | ||
44 | set -- /srv/nbd.btrfs | ||
45 | elif [ "$(blockdev --getsz /dev/nbd0)" -gt 0 ]; then | ||
46 | (set -x; dd if=/dev/nbd0 of=/srv/nbd.btrfs~ && mv /srv/nbd.btrfs~ /srv/nbd.btrfs) || die "failed to copy network block device" | ||
47 | set -- /srv/nbd.btrfs | ||
48 | else | ||
49 | die "no input device and no input btrfs layers: aborting." | ||
50 | fi | ||
51 | fi | ||
52 | |||
53 | for fs; do | ||
54 | [ -f "$fs" ] || die "not a file: $fs" | ||
55 | case "$fs" in | ||
56 | *.btrfs) ;; | ||
57 | *) die "invalid name (does not match *.btrfs): $fs" ;; | ||
58 | esac | ||
59 | shift | ||
60 | set -- "$@" "rootfs/${fs##*/}=$fs" | ||
61 | done | ||
62 | |||
63 | |||
64 | whole_device() | 3 | whole_device() |
65 | { | 4 | { |
66 | case "$1" in | 5 | case "$1" in |
@@ -133,6 +72,75 @@ generate_keys() | |||
133 | fi | 72 | fi |
134 | } | 73 | } |
135 | 74 | ||
75 | try_mount() | ||
76 | { | ||
77 | # TODO: don't use /mnt | ||
78 | # Ofc the real solution is to get help with xorriso. | ||
79 | NEED_UNMOUNT="$1" | ||
80 | mount -r "$1" /mnt && trap 'umount -l /mnt' EXIT | ||
81 | } | ||
82 | |||
83 | |||
84 | . samizdat-paths.sh || exit 1 | ||
85 | |||
86 | outdev= | ||
87 | volid=SamizdatLive | ||
88 | gpg_iso_path=gnupghome | ||
89 | gnupghome= | ||
90 | child_dir=$samizdat_child_dir/child.$$ | ||
91 | vmlinuz_dir=$samizdat_linux_dir | ||
92 | efi_dir=$samizdat_grub_efi_dir | ||
93 | |||
94 | die() { printf "%s: Error: %s\n" "$0" "$*" >&2; exit 1; } | ||
95 | |||
96 | TEMP="$(getopt -o '' --long bootloader,reuse-child:,adam,usb,detach,in:,out:,test -n "$0" -- "$@")" || | ||
97 | die 'getopt error' | ||
98 | eval set -- "$TEMP" | ||
99 | |||
100 | ADAM=; DETACH=; USB=y | ||
101 | while [ $# -gt 0 ]; do | ||
102 | case "$1" in | ||
103 | --adam) shift; ADAM=y;; | ||
104 | --bootloader) shift; BOOTLOADER_ONLY=y;; | ||
105 | --cdrom) shift; USB=;; | ||
106 | --detach) shift; DETACH=y;; | ||
107 | --test) shift; QUICK_TEST=y;; | ||
108 | --out) CMDLINE_OUTDEV="$2"; USB=; shift 2;; | ||
109 | --in) INPUT_DEVICE="$2"; shift 2;; | ||
110 | --reuse-child) REUSE_CHILD=y; child_dir=$samizdat_child_dir/child."$2"; shift 2;; | ||
111 | --) shift; break;; | ||
112 | *) die 'getopt error';; | ||
113 | esac | ||
114 | done | ||
115 | |||
116 | if [ "$INPUT_DEVICE" ]; then | ||
117 | die "support for --in is disabled because xorriso needs different arguments to produce a bootable image" | ||
118 | |||
119 | elif [ $# = 0 -a -z "$BOOTLOADER_ONLY" ]; then | ||
120 | if mountpoint -q /cdrom; then | ||
121 | INPUT_DEVICE=/cdrom | ||
122 | elif [ -e debian-live-8.4.0-amd64-standard.btrfs -a -e layer.btrfs ]; then | ||
123 | set -- debian-live-8.4.0-amd64-standard.btrfs layer.btrfs | ||
124 | elif [ -e /srv/nbd.btrfs ]; then | ||
125 | set -- /srv/nbd.btrfs | ||
126 | elif [ "$(blockdev --getsz /dev/nbd0)" -gt 0 ]; then | ||
127 | (set -x; dd if=/dev/nbd0 of=/srv/nbd.btrfs~ && mv /srv/nbd.btrfs~ /srv/nbd.btrfs) || die "failed to copy network block device" | ||
128 | set -- /srv/nbd.btrfs | ||
129 | else | ||
130 | die "no input device and no input btrfs layers: aborting." | ||
131 | fi | ||
132 | fi | ||
133 | |||
134 | for fs; do | ||
135 | [ -f "$fs" ] || die "not a file: $fs" | ||
136 | case "$fs" in | ||
137 | *.btrfs) ;; | ||
138 | *) die "invalid name (does not match *.btrfs): $fs" ;; | ||
139 | esac | ||
140 | shift | ||
141 | set -- "$@" "rootfs/${fs##*/}=$fs" | ||
142 | done | ||
143 | |||
136 | 144 | ||
137 | [ "$(id -u)" = 0 ] || die "you are not root." | 145 | [ "$(id -u)" = 0 ] || die "you are not root." |
138 | 146 | ||
@@ -147,14 +155,6 @@ else | |||
147 | generate_keys | 155 | generate_keys |
148 | fi | 156 | fi |
149 | 157 | ||
150 | try_mount() | ||
151 | { | ||
152 | # TODO: don't use /mnt | ||
153 | # Ofc the real solution is to get help with xorriso. | ||
154 | NEED_UNMOUNT="$1" | ||
155 | mount -r "$1" /mnt && trap 'umount -l /mnt' EXIT | ||
156 | } | ||
157 | |||
158 | if [ "$INPUT_DEVICE" ]; then | 158 | if [ "$INPUT_DEVICE" ]; then |
159 | if [ "$INPUT_DEVICE" = /dev/md55 ]; then | 159 | if [ "$INPUT_DEVICE" = /dev/md55 ]; then |
160 | if mountpoint -q /cdrom; then | 160 | if mountpoint -q /cdrom; then |