diff options
Diffstat (limited to 'src/xorriso-usb.sh')
-rw-r--r-- | src/xorriso-usb.sh | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/src/xorriso-usb.sh b/src/xorriso-usb.sh new file mode 100644 index 0000000..61fcda0 --- /dev/null +++ b/src/xorriso-usb.sh | |||
@@ -0,0 +1,182 @@ | |||
1 | #!/bin/bash | ||
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 | ||
10 | vmlinuz_dir=$samizdat_isolinux_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 adam,usb,detach,out:,test -n "$0" -- "$@")" || | ||
16 | die 'getopt error' | ||
17 | eval set -- "$TEMP" | ||
18 | |||
19 | ADAM=; DETACH=; USB= | ||
20 | while [ $# -gt 0 ]; do | ||
21 | case "$1" in | ||
22 | --adam) shift; ADAM=y;; | ||
23 | --usb) shift; USB=y;; | ||
24 | --detach) shift; DETACH=y;; | ||
25 | --test) shift; QUICK_TEST=y;; | ||
26 | --out) CMDLINE_OUTDEV="$2"; shift 2;; | ||
27 | --) shift; break;; | ||
28 | *) die 'getopt error';; | ||
29 | esac | ||
30 | done | ||
31 | |||
32 | if [ $# = 0 ]; then | ||
33 | set -- debian-live-8.4.0-amd64-standard.btrfs layer.btrfs | ||
34 | fi | ||
35 | |||
36 | for fs; do | ||
37 | [ -f "$fs" ] || die "not a file: $fs" | ||
38 | shift | ||
39 | set -- "$@" "rootfs/${fs##*/}=$fs" | ||
40 | done | ||
41 | |||
42 | |||
43 | whole_device() | ||
44 | { | ||
45 | case "$1" in | ||
46 | *-part?) false ;; | ||
47 | *-part??) false ;; | ||
48 | *-part???) false ;; | ||
49 | */usb\*) false ;; | ||
50 | *) true ;; | ||
51 | esac | ||
52 | } | ||
53 | |||
54 | confirm_usb() | ||
55 | { | ||
56 | local msg="This will completely overwrite device:\n\n\t%s\n\nType 'yes' to confirm.\nContinue? " | ||
57 | printf "$msg" "$1" >&2 | ||
58 | read line | ||
59 | case "$line" in | ||
60 | [yY][eE][sS]) return ;; | ||
61 | *) die "Aborted by user." ;; | ||
62 | esac | ||
63 | } | ||
64 | |||
65 | choose_usb() | ||
66 | { | ||
67 | local devs maj | ||
68 | set -- /dev/disk/by-id/usb* | ||
69 | for dev; do | ||
70 | shift | ||
71 | whole_device "$dev" || continue | ||
72 | set -- "$@" "$dev" | ||
73 | done | ||
74 | if [ $# = 0 ]; then | ||
75 | die "no usb device found" | ||
76 | elif [ $# = 1 ]; then | ||
77 | confirm_usb "$1" || die impossible | ||
78 | outdev="$1" | ||
79 | else | ||
80 | die "multiple USB devices connected and choice between them is unimplemented. ($*)" | ||
81 | fi | ||
82 | } | ||
83 | |||
84 | choose_cdrom() | ||
85 | { | ||
86 | die 'choose_cdrom: unimplemented' | ||
87 | } | ||
88 | |||
89 | choose_outdev() | ||
90 | { | ||
91 | if [ "$CMDLINE_OUTDEV" ]; then | ||
92 | outdev=$CMDLINE_OUTDEV~ | ||
93 | NEED_STDIO=y | ||
94 | elif [ "$USB" ]; then | ||
95 | choose_usb | ||
96 | NEED_STDIO=y | ||
97 | else | ||
98 | choose_cdrom | ||
99 | NEED_STDIO= | ||
100 | fi | ||
101 | } | ||
102 | |||
103 | generate_keys() | ||
104 | { | ||
105 | if [ "$ADAM" ]; then | ||
106 | kiki init || die 'kiki init failed' | ||
107 | gnupghome=/root/.gnupg | ||
108 | else | ||
109 | keygen.sh "$child_dir" || die "keygen.sh failed" | ||
110 | gnupghome=$child_dir/root/.gnupg | ||
111 | trap 'umount "$child_dir"; rmdir "$child_dir"' EXIT | ||
112 | fi | ||
113 | } | ||
114 | |||
115 | |||
116 | [ "$(id -u)" = 0 ] || die "you are not root." | ||
117 | |||
118 | grub-efi.sh || die "grub-efi.sh failed" | ||
119 | |||
120 | choose_outdev | ||
121 | |||
122 | generate_keys | ||
123 | |||
124 | if [ "$INPUT_DEVICE" ]; then | ||
125 | REPLACE_INITRD= | ||
126 | REMOVE_BTRFS= | ||
127 | ADD_BTRFS= | ||
128 | else | ||
129 | REPLACE_INITRD=y | ||
130 | REMOVE_BTRFS=y | ||
131 | ADD_BTRFS=y | ||
132 | fi | ||
133 | |||
134 | if [ "$QUICK_TEST" ]; then | ||
135 | REMOVE_BTRFS=y | ||
136 | ADD_BTRFS= | ||
137 | fi | ||
138 | |||
139 | if [ "$REPLACE_INITRD" ]; then | ||
140 | initrd.sh | ||
141 | fi | ||
142 | |||
143 | (set -x | ||
144 | xorriso \ | ||
145 | ${INPUT_DEVICE:+ -indev "$INPUT_DEVICE" } \ | ||
146 | -outdev ${NEED_STDIO:+stdio:}"$outdev" \ | ||
147 | -blank as_needed \ | ||
148 | -report_about mishap \ | ||
149 | -return_with sorry 0 \ | ||
150 | -volid "$volid" \ | ||
151 | -pathspecs on \ | ||
152 | \ | ||
153 | \ | ||
154 | ${REPLACE_INITRD:+ -rm_r linux -- -add linux="${vmlinuz_dir}" -- } \ | ||
155 | ${REMOVE_BTRFS:+ -rm_r btrfs -- } \ | ||
156 | ${ADD_BTRFS:+ -follow link -add "$@" -- -follow default } \ | ||
157 | \ | ||
158 | \ | ||
159 | -rm_r "${gpg_iso_path}" -- \ | ||
160 | -add "${gpg_iso_path}=${gnupghome}" -- \ | ||
161 | \ | ||
162 | \ | ||
163 | -chown_r 0 / -- \ | ||
164 | -chgrp_r 0 / -- \ | ||
165 | -chmod_r go-rwx "${gpg_iso_path}" -- \ | ||
166 | \ | ||
167 | \ | ||
168 | -as mkisofs -graft-points \ | ||
169 | -b grub/i386-pc/eltorito.img \ | ||
170 | -no-emul-boot -boot-info-table \ | ||
171 | --embedded-boot "${efi_dir}"/embedded.img \ | ||
172 | --protective-msdos-label \ | ||
173 | grub="${efi_dir}"/grub | ||
174 | ) || die "xorriso exited $?" | ||
175 | |||
176 | case "$outdev" in | ||
177 | *~) [ -f "$outdev" ] && mv "$outdev" "${outdev%\~}" ;; | ||
178 | esac | ||
179 | |||
180 | if [ "$USB" -a "$DETACH" -a $? = 0 ]; then | ||
181 | udisks --detach "$outdev" | ||
182 | fi | ||