diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2020-01-27 09:20:02 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2020-01-27 09:20:02 +0200 |
commit | 2c60db6de7dc2870b60e603d6f3eb2900fb5966f (patch) | |
tree | 2fd9cbdc31e7a23cdb45f70346c2016f4f27f9cf | |
parent | ed9ef80480d01e6a3d14e68bac075d2efac25514 (diff) |
Add ability to specify user, target directory in upload-machine
-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. |