diff options
Diffstat (limited to 'share')
-rw-r--r-- | share/trashman/trashman/functions | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/share/trashman/trashman/functions b/share/trashman/trashman/functions index 78d527b..61102e9 100644 --- a/share/trashman/trashman/functions +++ b/share/trashman/trashman/functions @@ -224,3 +224,39 @@ trashman_check_sudo () { export SUDO="sudo" fi } + +# Deploy to a remote server +trashman_deploy () { + SERVER="$2" + RSYNC_PATH="sudo rsync" + DEPLOY_RSYNC="rsync -rltDv --no-perms --no-owner --delete --rsync-path" + SSH="ssh -T -q -o ConnectTimeout=15" + + trashman_echo "Deploying to $SERVER..." + + # Check remote environment + $SSH $SERVER <<EOF + ##### BEGIN REMOTE SCRIPT ##### + # Check for passwordless sudo + # See references like https://raymii.org/s/articles/Check_if_passwordless_sudo_can_be_used_in_a_bash_script_or_nagios_check.html + if ! sudo -n true; then + echo "Please set passwordless sudo on $SERVER." + echo "You can do that by adding the following line on /etc/sudoers.d/local:" + echo "" + echo "%sudo ALL=NOPASSWD: ALL" + echo "" + echo "And make sure your user is included in the 'sudo' group." + exit 1 + fi + ##### END REMOTE SCRIPT ####### +EOF + + # Check connection + if [ "$?" != "0" ]; then + trashman_echo "Error connecting or setting up $FQDN." + exit 1 + fi + + $DEPLOY_RSYNC "$RSYNC_PATH" $APP_BASE/ $SERVER:/usr/local/share/trashman/ + $SSH $SERVER sudo /usr/local/share/trashman/trashman install trashman +} |