bitreich-drist

fork of bitreich.org/drist
git clone git://git.pyratebeard.net/bitreich-drist.git
Log | Files | Refs | README | LICENSE

commit c9735fd7d912dbca6e03c2725456d4eeb6d9487b
parent 723d94faa06c4597f88ccfdcf7821154bf889138
Author: Solene Rapenne <solene@perso.pw>
Date:   Thu, 29 Nov 2018 08:20:10 +0100

New option for using sudo/doas on remote server

Diffstat:
Mdrist | 46+++++++++++++++++++++++++++++++++++++---------
Mdrist.1 | 14++++++++++++--
2 files changed, 49 insertions(+), 11 deletions(-)

diff --git a/drist b/drist @@ -1,8 +1,36 @@ #!/bin/sh +usage() { + echo "$0 [-s [-e sudo|doas]] server" + exit 0 +} + + +while getopts se: arg; do + case ${arg} in + s) SUDO=1 ;; + e) SUDO_BIN="${OPTARG}" ;; + *) usage ;; + esac +done +shift $((OPTIND - 1)) + +# allow to use a privilege escalation program +if [ "$SUDO" -eq 1 ] +then + # defaulting to sudo + if [ -z "$SUDO_BIN" ] + then + SUDO_BIN=sudo + fi + EXEC="$SUDO_BIN" +else + EXEC="" +fi + +# check if host exists if [ "$#" -ne 1 ]; then - echo "You should pass a server as a parameter" - exit 1 + usage else HOSTNAME=$(ssh "$1" "uname -n") if [ "$?" -ne 0 ]; then @@ -22,7 +50,7 @@ copy_files() { then printf 'Copying files:\n' find "${1}"/ -type f | cut -d '/' -f 2- | tee "${LIST}" - rsync -lD --files-from="${LIST}" "${1}/" "${2}":/ + rsync --rsync-path="${EXEC} rsync" -lD --files-from="${LIST}" "${1}/" "${2}":/ rm "$LIST" fi fi @@ -34,11 +62,11 @@ remote_script() { if [ -f "${1}" ] then printf 'Executing script\n' - ssh "${2}" 'DRIST=$(mktemp /tmp/drist.XXXXXXXXXXXX) && - cat - > "$DRIST" && - chmod u+x "$DRIST" && - "$DRIST" ; - rm "$DRIST"' < "$1" + ssh "${2}" "DRIST=$(mktemp /tmp/drist.XXXXXXXXXXXX) && + cat - > \$DRIST && + chmod u+x \$DRIST && + ${EXEC} \$DRIST ; + rm \$DRIST" < "$1" fi } @@ -54,7 +82,7 @@ delete_files() { printf 'Removing files:\n' find "$1" -type f | sed 's/"/\\&/' | \ awk -v path="${1}" '{ printf "\"%s\" ",substr($0,length(path)+1)}' > "${LIST}" - test -s "$LIST" && ssh "$2" "rm -v $(cat $LIST)" + test -s "$LIST" && ssh "$2" "${EXEC} rm -v $(cat $LIST)" fi fi } diff --git a/drist.1 b/drist.1 @@ -6,7 +6,18 @@ .Nd dumb remote installer shell tool, a remote deployment tool .Sh SYNOPSIS .Nm +.Op Fl s Op Fl e Ar sudo|doas .Ar server +.Sh OPTIONS +.Op Fl s +use a program to execute a command as root on the remote server. +Default is sudo. + +.Op Fl e Ar binary +binary to use for executing the commands as root. +This flag is only useful when used with +.Fl s . + .Sh DESCRIPTION .Nm is a tool to configure remote servers using @@ -14,8 +25,7 @@ is a tool to configure remote servers using and .Xr rsync 1 . .Nm -has been designed to be simple, so it may not offer all the features -you want. +has been designed to be simple, so it may not offer all the features you want. .Pp When you run .Nm