aboutsummaryrefslogtreecommitdiff
path: root/upload-machine
diff options
context:
space:
mode:
Diffstat (limited to 'upload-machine')
-rwxr-xr-xupload-machine37
1 files changed, 24 insertions, 13 deletions
diff --git a/upload-machine b/upload-machine
index fa7aac9..19544fa 100755
--- a/upload-machine
+++ b/upload-machine
@@ -37,8 +37,8 @@ while [ "$#" -gt 0 ]; do
done
host="$1"
-newsv="$2"
-oldsv="$3"
+newsv="${2%/}"
+oldsv="${3%/}"
if [ -z "$host" -o -z "$newsv" ]; then
error "$usage"
@@ -46,10 +46,21 @@ fi
host="build@$host"
+newsv_name="$(sed -n -re 's%^(.*/)?([^/]+)$%\2%p' <<<"$newsv")"
+oldsv_name="$(sed -n -re 's%^(.*/)?([^/]+)$%\2%p' <<<"$oldsv")"
+
+if [ -z "$newsv_name" ]; then
+ error "unable to extract subvolume name from '$newsv'"
+fi
+
+if [ -n "$oldsv" -a -z "$oldsv_name" ]; then
+ error "unable to extract subvolume name from '$oldsv'"
+fi
+
# Get the machine link (<name>-<P>) and name.
#
-mlink="$(echo "$newsv" | sed -n -re 's/^(.+-[0-9]+)\.[0-9]+$/\1/p')"
-mname="$(echo "$mlink" | sed -n -re 's/^(.+)-[0-9]+$/\1/p')"
+mlink="$(sed -n -re 's/^(.+-[0-9]+)\.[0-9]+$/\1/p' <<<"$newsv_name")"
+mname="$(sed -n -re 's/^(.+)-[0-9]+$/\1/p' <<<"$mlink")"
if [ -z "$mlink" -o -z "$mname" ]; then
error "unable to extract machine link/name from '$newsv'"
@@ -57,8 +68,8 @@ fi
# Subvolume paths on build host.
#
-newsv_path="$machines/$mname/$newsv"
-oldsv_path="$machines/$mname/$oldsv"
+newsv_host="$machines/$mname/$newsv_name"
+oldsv_host="$machines/$mname/$oldsv_name"
# Make sure subvolumes are read-only.
#
@@ -98,14 +109,14 @@ sudo "${send[@]}" | ssh "$host" sudo btrfs receive "$machines/$mname/"
# Adjust machine ownership.
#
-ssh "$host" sudo btrfs property set -ts "$newsv_path" ro false
-ssh "$host" sudo chown build:build "$newsv_path"
-ssh "$host" sudo chown build:build "$newsv_path/*"
-ssh "$host" btrfs property set -ts "$newsv_path" ro true
+ssh "$host" sudo btrfs property set -ts "$newsv_host" ro false
+ssh "$host" sudo chown build:build "$newsv_host"
+ssh "$host" sudo chown build:build "$newsv_host/*"
+ssh "$host" btrfs property set -ts "$newsv_host" ro true
# Atomically switch the current machine.
#
-ssh "$host" "cd $machines/$mname && ln -s $newsv new-$mlink"
+ssh "$host" "cd $machines/$mname && ln -s $newsv_name new-$mlink"
ssh "$host" "cd $machines/$mname && mv -T new-$mlink $mlink"
# Remove the old machine subvolume.
@@ -116,5 +127,5 @@ if [ -z "$oldsv" -o "$keep" = true ]; then
fi
set -x
-ssh "$host" btrfs property set -ts "$oldsv_path" ro false
-ssh "$host" btrfs subvolume delete "$oldsv_path"
+ssh "$host" btrfs property set -ts "$oldsv_host" ro false
+ssh "$host" btrfs subvolume delete "$oldsv_host"