diff options
-rwxr-xr-x | upload-machine | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/upload-machine b/upload-machine index 556f824..cffcd7b 100755 --- a/upload-machine +++ b/upload-machine @@ -2,16 +2,16 @@ # Upload new or upgrade existing machine subvolume on a Build OS build host. # -# -k - keep the old subvolume on the build host +# -k - keep the old subvolume on the target host +# -u <user> - target user instead of build +# -d <dir> - target machines directory instead of /build/machines/default # -# <host> - build host to upload to (as user 'build') +# <host> - build host to upload to (as user build by default) # <new-subvol> - machine subvolume to upload # <old-subvol> - previous machine subvolume (btrfs send -p) # usage="usage: $0 [<options>] <host> <new-subvol> [<old-subvol>]" -machines=/build/machines/default - owd="$(pwd)" trap "{ cd '$owd'; exit 1; }" ERR set -o errtrace # Trap in functions. @@ -20,6 +20,8 @@ function info () { echo "$*" 1>&2; } function error () { info "$*"; exit 1; } keep=false +user=build +machines=/build/machines/default while [ "$#" -gt 0 ]; do case "$1" in @@ -27,6 +29,16 @@ while [ "$#" -gt 0 ]; do keep=true shift ;; + -u) + shift + user="$1" + shift + ;; + -d) + shift + machines="$1" + shift + ;; -*) error "unknown option: $1" ;; @@ -44,7 +56,7 @@ if [ -z "$host" -o -z "$newsv" ]; then error "$usage" fi -host="build@$host" +host="$user@$host" newsv_name="$(sed -n -re 's%^(.*/)?([^/]+)$%\2%p' <<<"$newsv")" oldsv_name="$(sed -n -re 's%^(.*/)?([^/]+)$%\2%p' <<<"$oldsv")" @@ -66,7 +78,7 @@ if [ -z "$mlink" -o -z "$mname" ]; then error "unable to extract machine link/name from '$newsv'" fi -# Subvolume paths on build host. +# Subvolume paths on target host. # newsv_host="$machines/$mname/$newsv_name" oldsv_host="$machines/$mname/$oldsv_name" @@ -110,8 +122,8 @@ sudo "${send[@]}" | ssh "$host" sudo btrfs receive "$machines/$mname/" # Adjust machine ownership. # 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" sudo chown "$user:$user" "$newsv_host" +ssh "$host" sudo chown "$user:$user" "$newsv_host/*" ssh "$host" btrfs property set -ts "$newsv_host" ro true # Atomically switch the current machine. |