summaryrefslogtreecommitdiff
path: root/btrfs-functions.sh
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2016-04-22 16:03:26 -0400
committerAndrew Cady <d@jerkface.net>2016-04-22 18:50:58 -0400
commit59df1261e0dc123c22dde588ced5c3abbf8300ca (patch)
tree0d43897973fd866f32cb11c202fb26a521d94f7e /btrfs-functions.sh
parent727026bb76dc2e9cbc4d935db5eb03049d65385e (diff)
updated btrfs send/recv code; script to put layered seed on iso
Diffstat (limited to 'btrfs-functions.sh')
-rw-r--r--btrfs-functions.sh42
1 files changed, 33 insertions, 9 deletions
diff --git a/btrfs-functions.sh b/btrfs-functions.sh
index 3648c24..b83b94d 100644
--- a/btrfs-functions.sh
+++ b/btrfs-functions.sh
@@ -100,28 +100,52 @@ btrfs_show_default_path()
100 mp=$(btrfs_get_mountpoint "$mp") || die # TODO: fix caller? 100 mp=$(btrfs_get_mountpoint "$mp") || die # TODO: fix caller?
101 btrfs_mountpoint "$mp" || die "not a mountpoint: $mp" 101 btrfs_mountpoint "$mp" || die "not a mountpoint: $mp"
102 path=$(btrfs subvolume get-default "$mp"/|sed -n -e 's/.* path //p') 102 path=$(btrfs subvolume get-default "$mp"/|sed -n -e 's/.* path //p')
103 printf '%s\n' "$mp/$path" 103 if [ "$path" ]; then
104 printf '%s\n' "$mp/$path"
105 else
106 printf '%s\n' "$mp"
107 fi
108}
109
110btrfs_show_default_id()
111{
112 $(ARGS_NE mp)
113 local id
114 mp=$(btrfs_get_mountpoint "$mp") || die # TODO: fix caller?
115 btrfs_mountpoint "$mp" || die "not a mountpoint: $mp"
116 id=$(btrfs subvolume get-default "$mp"/|sed -n -e 's/^ID \([^ ]*\) .*/\1/p')
117 [ "$id" ] || return
118 echo $id
104} 119}
105 120
106btrfs_replace_default_subvolume_with() 121btrfs_replace_default_subvolume_with()
107{ 122{
108 $(ARGS_NE new_default) 123 $(ARGS_NE new_default)
109 local old_default subvol_id 124 local old_default old_default_id new_default_id
110 old_default=$(btrfs_show_default_path "$new_default") || die 125 old_default_id=$(btrfs_show_default_id "$new_default") || die
126 new_default_id=$(btrfs_show_subvolume_id "$new_default") || die
127
128 [ "$new_default_id" = "$old_default_id" ] && return
129
130 if [ "$old_default_id" != 5 ]; then
131 old_default=$(btrfs_show_default_path "$new_default") || die
132 else
133 old_default=
134 fi
111 135
112 [ "$new_default" = "$old_default" ] && return 136 btrfs subvolume set-default "$new_default_id" "$new_default" || die
113 137
114 subvol_id=$(btrfs_show_subvolume_id "$new_default") || die 138 if [ "$old_default" ]; then
115 btrfs subvolume set-default "$subvol_id" "$new_default" || die 139 btrfs subvolume delete "$old_default"
116 btrfs subvolume delete "$old_default" 140 sex mv "$new_default" "$old_default"
117 sex mv "$new_default" "$old_default" 141 fi
118} 142}
119 143
120btrfs_show_subvolume_id() 144btrfs_show_subvolume_id()
121{ 145{
122 $(ARGS_NE path) 146 $(ARGS_NE path)
123 local result 147 local result
124 result=$(btrfs subvolume show "$path" | sed -n -e 's/^[ \t]*Subvolume ID:[ \t]*//p') 148 result=$(btrfs subvolume show "$path" | sed -n -e 's/^[ \t]*Subvolume ID:[ \t]*//p; s/.*is toplevel subvolume/5/p')
125 if [ "$result" ] 149 if [ "$result" ]
126 then printf '%s\n' "$result" 150 then printf '%s\n' "$result"
127 else false 151 else false