diff options
-rwxr-xr-x | samizdat-eject.sh | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/samizdat-eject.sh b/samizdat-eject.sh index ac2ebc3..e9e71e5 100755 --- a/samizdat-eject.sh +++ b/samizdat-eject.sh | |||
@@ -1,4 +1,15 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | die() | ||
3 | { | ||
4 | printf '%s\n' "$*" >&2 | ||
5 | exit 1 | ||
6 | } | ||
7 | |||
8 | target=$1 | ||
9 | |||
10 | [ "$target" ] || die "Usage: $0 <target filename>" | ||
11 | [ ! -e "$target" ] || die "Error: file exists: $target" | ||
12 | |||
2 | 13 | ||
3 | . mdadm-dup.sh || exit 1 | 14 | . mdadm-dup.sh || exit 1 |
4 | 15 | ||
@@ -10,10 +21,6 @@ btrfs_subdevices() | |||
10 | 21 | ||
11 | devices=$(btrfs_subdevices /) || exit 1 | 22 | devices=$(btrfs_subdevices /) || exit 1 |
12 | 23 | ||
13 | target=$1 | ||
14 | |||
15 | [ -e "$target" ] && exit 1 | ||
16 | |||
17 | set -- | 24 | set -- |
18 | seen= | 25 | seen= |
19 | for dev in $devices; do | 26 | for dev in $devices; do |
@@ -23,7 +30,7 @@ for dev in $devices; do | |||
23 | /dev/mapper/samizdatcrypt) seen=y ;; | 30 | /dev/mapper/samizdatcrypt) seen=y ;; |
24 | esac | 31 | esac |
25 | done | 32 | done |
26 | [ "$seen" ] || exit 1 | 33 | [ "$seen" ] || set -- # avoid messing up someone's btrfs! |
27 | 34 | ||
28 | copy() | 35 | copy() |
29 | { | 36 | { |
@@ -34,6 +41,8 @@ remove() | |||
34 | { | 41 | { |
35 | for dev; do | 42 | for dev; do |
36 | (set -x; btrfs device remove "$dev" /) | 43 | (set -x; btrfs device remove "$dev" /) |
44 | dmsetup remove "$dev" | ||
45 | losetup -D | ||
37 | done | 46 | done |
38 | } | 47 | } |
39 | 48 | ||