Skip to content

Commit

Permalink
Added support for args and stdin to provision.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
dmotte committed Nov 27, 2023
1 parent 4d25ed7 commit 20dd021
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions scripts/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
'

0 comments on commit 20dd021

Please sign in to comment.