From 20dd0211ff1858c355625a3ef47c1651ea47f970 Mon Sep 17 00:00:00 2001 From: dmotte <37443982+dmotte@users.noreply.github.com> Date: Tue, 28 Nov 2023 00:53:12 +0100 Subject: [PATCH] Added support for args and stdin to provision.sh --- scripts/provision.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/scripts/provision.sh b/scripts/provision.sh index 8b7f259..9b642ac 100644 --- a/scripts/provision.sh +++ b/scripts/provision.sh @@ -2,22 +2,32 @@ set -e -# Provision a remote server using a Bash script -# Usage example: ./provision.sh provisioning/ user@hostname -p2222 +# Provision a remote server using a directory with a Bash script +# Usage example: +# ./provision.sh provisioning/ '--arg01 --arg02' ssh user@hostname -p2222 -cd "$1"; shift +prov_dir="$1"; shift +remote_args="$1"; shift -if [ ! -f main.sh ]; then +if [ ! -f "$prov_dir/main.sh" ]; then echo 'File main.sh not found' >&2 exit 1 fi -tar -cvzf- . | ssh "$@" ' +# Operations are split in two separate connections because we want the +# "$prov_dir/main.sh" script to be able to read from our stdin + +tar -cvzf- -C "$prov_dir" . | "$@" ' set -ex rm -rf /tmp/provisioning mkdir /tmp/provisioning tar -xvzf- -C/tmp/provisioning - bash /tmp/provisioning/main.sh || result="$?" +' + +# shellcheck disable=SC2016 +"$@" ' + set -ex + bash /tmp/provisioning/main.sh '"$remote_args"' || result="$?" rm -rf /tmp/provisioning exit "${result:-0}" '