summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/xorriso-usb.sh138
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
5outdev=
6volid=SamizdatLive
7gpg_iso_path=gnupghome
8gnupghome=
9child_dir=$samizdat_child_dir/child.$$
10vmlinuz_dir=$samizdat_linux_dir
11efi_dir=$samizdat_grub_efi_dir
12
13die() { printf "%s: Error: %s\n" "$0" "$*" >&2; exit 1; }
14
15TEMP="$(getopt -o '' --long bootloader,reuse-child:,adam,usb,detach,in:,out:,test -n "$0" -- "$@")" ||
16 die 'getopt error'
17eval set -- "$TEMP"
18
19ADAM=; DETACH=; USB=y
20while [ $# -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
33done
34
35if [ "$INPUT_DEVICE" ]; then
36 die "support for --in is disabled because xorriso needs different arguments to produce a bootable image"
37
38elif [ $# = 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
51fi
52
53for 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"
61done
62
63
64whole_device() 3whole_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
75try_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
86outdev=
87volid=SamizdatLive
88gpg_iso_path=gnupghome
89gnupghome=
90child_dir=$samizdat_child_dir/child.$$
91vmlinuz_dir=$samizdat_linux_dir
92efi_dir=$samizdat_grub_efi_dir
93
94die() { printf "%s: Error: %s\n" "$0" "$*" >&2; exit 1; }
95
96TEMP="$(getopt -o '' --long bootloader,reuse-child:,adam,usb,detach,in:,out:,test -n "$0" -- "$@")" ||
97 die 'getopt error'
98eval set -- "$TEMP"
99
100ADAM=; DETACH=; USB=y
101while [ $# -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
114done
115
116if [ "$INPUT_DEVICE" ]; then
117 die "support for --in is disabled because xorriso needs different arguments to produce a bootable image"
118
119elif [ $# = 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
132fi
133
134for 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"
142done
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
148fi 156fi
149 157
150try_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
158if [ "$INPUT_DEVICE" ]; then 158if [ "$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