diff options
author | Andrew Cady <d@jerkface.net> | 2016-04-26 04:08:56 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2016-04-26 04:08:56 -0400 |
commit | 19fc3ad482a467dbfcd27c8366ba026107498f4f (patch) | |
tree | 215c1290167cd213ed0b82bd9a9d23ea6bac2778 /samizdat-eject.sh | |
parent | c33cb424ef479a6947395391b3771cc56b2d6161 (diff) |
ejection script for cdrom duplication
included some necessary dependencies
Diffstat (limited to 'samizdat-eject.sh')
-rwxr-xr-x | samizdat-eject.sh | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/samizdat-eject.sh b/samizdat-eject.sh new file mode 100755 index 0000000..04ee610 --- /dev/null +++ b/samizdat-eject.sh | |||
@@ -0,0 +1,47 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . mdadm-dup.sh || exit 1 | ||
4 | |||
5 | btrfs_subdevices() | ||
6 | { | ||
7 | local mountpoint="$1" | ||
8 | btrfs filesystem show "$mountpoint" | sed -ne 's/^[ \t]*devid.* path //p' | ||
9 | } | ||
10 | |||
11 | devices=$(btrfs_subdevices /) || exit 1 | ||
12 | |||
13 | set -- | ||
14 | seen= | ||
15 | for dev in $devices; do | ||
16 | [ -b "$dev" ] || exit 1 | ||
17 | case "$dev" in | ||
18 | /dev/mapper/loop*) set -- "$@" "$dev" ;; | ||
19 | /dev/mapper/samizdatcrypt) seen=y ;; | ||
20 | esac | ||
21 | done | ||
22 | [ "$seen" ] || exit 1 | ||
23 | |||
24 | copy() | ||
25 | { | ||
26 | mdadm_copy_eject /dev/md55 /root/samizdat.iso | ||
27 | } | ||
28 | |||
29 | remove() | ||
30 | { | ||
31 | for dev; do | ||
32 | (set -x; btrfs device remove "$dev" /) | ||
33 | done | ||
34 | } | ||
35 | |||
36 | # Doing the mdadm copy before removing the devices means our filesystem includes | ||
37 | # devices that are ultimately backed by files ON THE SAME FILESYSTEM. As such, it | ||
38 | # might conceivably put btrfs into a deadlock of some kind. | ||
39 | |||
40 | # If it turns out this doesn't work, the order can be reversed. This will | ||
41 | # perform the read IO twice, though, almost doubling the total installation | ||
42 | # time. | ||
43 | |||
44 | copy & remove "$@" | ||
45 | |||
46 | set -x | ||
47 | wait | ||