kickstart/lib/kickstart-deploy
Bruno Tavares 41cf8f98bf Allows deployment scripts to be interactive
Previously, because we were piping the compiled script blob over ssh to
decompress over there without creating an intermediated bundled file, we
were allocating the stdin of the ssh session to have the read from the
pipe.

This blocked the allocation of the /dev/tty over the session and
prevented users to interact with the script. We would like some of the
interactions to work, like prompting for a confirmation or typing a
password.

To fix this, the deployment process was split in two steps. The first
step still receives the bundled file over a pipe, decompresses it on a
temprary folder, and outputs the location of the deployment folder.

We grab this output to feed on the second step, which has a script to go
to the deployment folder and start the execution.

Now, roles can make use of read, as well as sudo with password.
2015-09-26 22:36:18 -03:00

39 lines
735 B
Bash
Executable File

#!/bin/bash -e
[[ "$1" == "--sudo" ]] && prefix="sudo " && shift
[[ "$1" == "--password" ]] && shift && prefix="echo \"$1\" | sudo -S " && shift
target=$1
[ "$target" ] || echo "Please, provide an ssh target"
shift
[ "$DEBUG" ] && debug="-x"
kickstart compile "$@"
copy_command=$(
cat <<CMD
{
deploy_folder=\$(mktemp -d -t kickstart.XXXXX)
mkdir -p "\$deploy_folder"
cd "\$deploy_folder"
tar xz
echo "\$deploy_folder"
}
CMD
)
deploy_folder=$(tar chz -C compile . | ssh $target "bash -c '$copy_command'")
execute_command=$(
cat <<CMD
{
cd $deploy_folder
exit_status=0
$prefix bash $debug install.sh || exit_status=\$?
rm -rf "$deploy_folder"
exit \$exit_status
}
CMD
)
ssh $target "bash -c '$execute_command'"