aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-10-18 14:08:28 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-10-18 14:08:28 +0200
commit3793e65f9a57c598ffa412a52db1078c29b3ef65 (patch)
treed47a7b6b34e17f57861b0cf4eee03f96fc817920
parent071929539b26dfcb0fa3887e2fd6c0224ff2e5df (diff)
Fix bugs in upload-machine script
-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"