Add -p flag for persistent connections through the script - drist - a remote deployment tool HTML git clone git://bitreich.org/drist/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/drist/ DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit 1937be9bc7349fcd17b34d24cb3738fbba966d62 DIR parent 9131a56282d056474e4d59233dcf3ad2ec9b24cc HTML Author: Solene Rapenne <solene@perso.pw> Date: Fri, 15 Feb 2019 15:48:59 +0100 Add -p flag for persistent connections through the script Diffstat: M drist | 24 +++++++++++++++++++----- M drist.1 | 9 +++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) --- DIR diff --git a/drist b/drist @@ -4,17 +4,19 @@ SIMULATE=0 SUDO=0 SUDO_BIN=sudo EXEC="" +SSHONCE=0 usage() { echo "$0 [-n] [-s [-e sudo|doas]] server" exit 0 } -while getopts nse: arg; do +while getopts pnse: arg; do case ${arg} in n) SIMULATE=1 ;; s) SUDO=1 ;; e) SUDO_BIN="${OPTARG}" ;; + p) SSHONCE=1 ;; *) usage ;; esac done @@ -26,11 +28,17 @@ then EXEC="$SUDO_BIN" fi +# use ControlMaster to make connections persistent +if [ "$SSHONCE" -eq 1 ] +then + SSH_PARAMS=-o"ControlMaster=auto"" "-o"ControlPath=/tmp/drist_ssh_%h_%p_%r.sock"" "-o"ControlPersist=1m" +fi + # check if host exists if [ "$#" -ne 1 ]; then usage else - HOSTNAME=$(ssh "$1" "${EXEC} uname -n") + HOSTNAME=$(ssh $SSH_PARAMS "$1" "${EXEC} uname -n") if [ "$?" -ne 0 ]; then echo "Error while ssh ${1}" exit 2 @@ -50,7 +58,7 @@ copy_files() { find "${1}"/ -type f | cut -d '/' -f 2- | tee "${LIST}" | sed 's/^/ \//' if [ "$SIMULATE" -ne 1 ] then - rsync --rsync-path="${EXEC} rsync" -lD --files-from="${LIST}" "${1}/" "${2}":/ + rsync -e "ssh $SSH_PARAMS" --rsync-path="${EXEC} rsync" -lD --files-from="${LIST}" "${1}/" "${2}":/ fi rm "$LIST" fi @@ -65,7 +73,7 @@ remote_script() { printf 'Executing file "%s":\n' "$1" if [ "$SIMULATE" -ne 1 ] then - ssh "${2}" "DRIST=$(mktemp /tmp/drist.XXXXXXXXXXXX) && + ssh $SSH_PARAMS "${2}" "DRIST=$(mktemp /tmp/drist.XXXXXXXXXXXX) && cat - > \$DRIST && chmod u+x \$DRIST && ${EXEC} \$DRIST ; @@ -91,7 +99,7 @@ delete_files() { if [ "$SIMULATE" -ne 1 ] then - test -s "$LIST" && ssh "$2" "${EXEC} rm $(cat $LIST)" + test -s "$LIST" && ssh $SSH_PARAMS "$2" "${EXEC} rm $(cat $LIST)" fi rm $LIST fi @@ -105,3 +113,9 @@ remote_script "script" "$1" remote_script "script-${HOSTNAME}" "$1" delete_files "absent" "$1" delete_files "absent-${HOSTNAME}" "$1" + +# close socket if persistance is actived +if [ "$SSHONCE" -eq 1 ] +then + ssh $SSH_PARAMS -O exit -N "$1" +fi DIR diff --git a/drist.1 b/drist.1 @@ -6,10 +6,17 @@ .Nd dumb remote installer shell tool, a remote deployment tool .Sh SYNOPSIS .Nm +.Op Fl p .Op Fl n .Op Fl s Op Fl e Ar sudo|doas .Ar server .Sh OPTIONS +.Op Fl p +to use persistent ssh connection, allowing to ssh only once +for the differents steps. +This uses ControlMaster feature from +.Xr ssh 1 . + .Op Fl n to simulate. Tells @@ -118,6 +125,8 @@ distribution. .Ex -std drist .Sh SEE ALSO .Xr rsync 1 +.Xr ssh 1 +.Xr ssh_config 5 .Sh Authors .An -nosplit The