apply/push
2018-06-26 15:07:22 +02:00

45 lines
741 B
Bash
Executable file

#!/bin/bash
set -e
set -u
function usage() {
echo "usage: $(basename "$0") [-v] <target> [<target>...] <user@remote>"
exit 1
}
if [[ -z "${APPLY_ROOT:-}" ]]; then
APPLY_ROOT="."
fi
if [[ $# -lt 1 ]]; then
usage
fi
if [[ "$1" == "-v" ]]; then
vflag='-v'
shift
else
vflag=''
fi
if [[ $# -lt 2 ]]; then
usage
fi
targets=()
while [[ $# -gt 1 ]]; do
targets+=("$1")
shift
done
remote="$1"
tmp=$(ssh "$remote" 'mktemp -d')
echo -e -n "\033[33m** pushing to\033[0m $remote:$tmp"
if scp -q -r "${APPLY_ROOT}"/{groups,units} run lib "$remote":"$tmp"; then
echo -e " \033[32mOK\033[0m"
fi
# shellcheck disable=SC2029
ssh -A "$remote" "cd '$tmp' && ./run $vflag ${targets[*]} && cd; rm -rf '$tmp'"