diff options
Diffstat (limited to 'btrfs-receive-root.sh')
-rw-r--r-- | btrfs-receive-root.sh | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/btrfs-receive-root.sh b/btrfs-receive-root.sh deleted file mode 100644 index f553c2c..0000000 --- a/btrfs-receive-root.sh +++ /dev/null | |||
@@ -1,55 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . sami/btrfs-functions.sh | ||
4 | . sami/var.sh | ||
5 | |||
6 | disable_stdout() { exec 3>&1; exec >&2; } | ||
7 | enable_stdout() { exec >&3; } | ||
8 | |||
9 | with_stdout() { enable_stdout; "$@"; disable_stdout; } | ||
10 | |||
11 | create_layer_filesystem() | ||
12 | { | ||
13 | [ ! -e "$layer_file" ] || return | ||
14 | ! mountpoint "$mountpoint" || return | ||
15 | mkdir -p "$mountpoint" && | ||
16 | sex dd if=/dev/zero of="$layer_file" bs=1M count="$layer_size" && | ||
17 | sex mount -o subvol=/,compress "$seed_file" "$mountpoint" && | ||
18 | layer_dev=$(losetup -f --show "$layer_file") && | ||
19 | sex btrfs device add "$layer_dev" "$mountpoint" && | ||
20 | mount -o rw,remount "$mountpoint" | ||
21 | } | ||
22 | |||
23 | finish() | ||
24 | { | ||
25 | local subv_id | ||
26 | sex mv "$mountpoint"/ROOT "$mountpoint"/ROOT.old || return | ||
27 | sex btrfs subvolume snapshot "$mountpoint"/"$receive_subv" "$mountpoint"/ROOT || return | ||
28 | subv_id=$(btrfs_show_subvolume_id "$mountpoint"/ROOT) || return | ||
29 | sex btrfs subvolume set-default "$subv_id" "$mountpoint" || return | ||
30 | sex btrfs subvolume delete "$mountpoint"/ROOT.old || return | ||
31 | umount "$mountpoint" || return | ||
32 | sex btrfstune -S1 "$layer_file" || return | ||
33 | losetup -d "$layer_dev" | ||
34 | } | ||
35 | |||
36 | set -e | ||
37 | disable_stdout | ||
38 | |||
39 | receive_dest=$1 | ||
40 | receive_subv=$2 | ||
41 | |||
42 | [ "$receive_subv" ] | ||
43 | [ "$receive_dest" ] | ||
44 | |||
45 | mountpoint=$(realpath -m --relative-base=. "$receive_dest") | ||
46 | |||
47 | seed_file=sami/debian-live-8.4.0-amd64-standard.btrfs | ||
48 | layer_file_FINAL=sami/debian-live-8.4.0-amd64-standard.layer.$receive_subv.btrfs | ||
49 | layer_file=$layer_file_FINAL.part | ||
50 | layer_size=1000 | ||
51 | |||
52 | create_layer_filesystem | ||
53 | with_stdout sex btrfs receive "$mountpoint" | ||
54 | finish | ||
55 | mv "$layer_file" "$layer_file_FINAL" | ||