From 2c60db6de7dc2870b60e603d6f3eb2900fb5966f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 27 Jan 2020 09:20:02 +0200 Subject: Add ability to specify user, target directory in upload-machine --- upload-machine | 28 ++++++++++++++++++++-------- 1 file 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 - target user instead of build +# -d - target machines directory instead of /build/machines/default # -# - build host to upload to (as user 'build') +# - build host to upload to (as user build by default) # - machine subvolume to upload # - previous machine subvolume (btrfs send -p) # usage="usage: $0 [] []" -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. -- cgit v1.1