summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsamizdat-eject.sh19
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
2die()
3{
4 printf '%s\n' "$*" >&2
5 exit 1
6}
7
8target=$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
11devices=$(btrfs_subdevices /) || exit 1 22devices=$(btrfs_subdevices /) || exit 1
12 23
13target=$1
14
15[ -e "$target" ] && exit 1
16
17set -- 24set --
18seen= 25seen=
19for dev in $devices; do 26for 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
25done 32done
26[ "$seen" ] || exit 1 33[ "$seen" ] || set -- # avoid messing up someone's btrfs!
27 34
28copy() 35copy()
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