summaryrefslogtreecommitdiff
path: root/src/btrfs-receive-root.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/btrfs-receive-root.sh')
-rw-r--r--src/btrfs-receive-root.sh55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/btrfs-receive-root.sh b/src/btrfs-receive-root.sh
new file mode 100644
index 0000000..f553c2c
--- /dev/null
+++ b/src/btrfs-receive-root.sh
@@ -0,0 +1,55 @@
1#!/bin/sh
2
3. sami/btrfs-functions.sh
4. sami/var.sh
5
6disable_stdout() { exec 3>&1; exec >&2; }
7enable_stdout() { exec >&3; }
8
9with_stdout() { enable_stdout; "$@"; disable_stdout; }
10
11create_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
23finish()
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
36set -e
37disable_stdout
38
39receive_dest=$1
40receive_subv=$2
41
42[ "$receive_subv" ]
43[ "$receive_dest" ]
44
45mountpoint=$(realpath -m --relative-base=. "$receive_dest")
46
47seed_file=sami/debian-live-8.4.0-amd64-standard.btrfs
48layer_file_FINAL=sami/debian-live-8.4.0-amd64-standard.layer.$receive_subv.btrfs
49layer_file=$layer_file_FINAL.part
50layer_size=1000
51
52create_layer_filesystem
53with_stdout sex btrfs receive "$mountpoint"
54finish
55mv "$layer_file" "$layer_file_FINAL"