| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 | 
							- #!/usr/bin/env sh
 
- ssh_deploy() {
 
-   _cdomain="$1"
 
-   _ckey="$2"
 
-   _ccert="$3"
 
-   _cca="$4"
 
-   _cfullchain="$5"
 
-   _cmdstr=""
 
-   _homedir='~'
 
-   _backupprefix="$_homedir/.acme_ssh_deploy/$_cdomain-backup"
 
-   _backupdir="$_backupprefix-$(_utc_date | tr ' ' '-')"
 
-   if [ -f "$DOMAIN_CONF" ]; then
 
-     
 
-     . "$DOMAIN_CONF"
 
-   fi
 
-   _debug _cdomain "$_cdomain"
 
-   _debug _ckey "$_ckey"
 
-   _debug _ccert "$_ccert"
 
-   _debug _cca "$_cca"
 
-   _debug _cfullchain "$_cfullchain"
 
-   
 
-   if [ -z "$ACME_DEPLOY_SSH_USER" ]; then
 
-     if [ -z "$Le_Deploy_ssh_user" ]; then
 
-       _err "ACME_DEPLOY_SSH_USER not defined."
 
-       return 1
 
-     fi
 
-   else
 
-     Le_Deploy_ssh_user="$ACME_DEPLOY_SSH_USER"
 
-     _savedomainconf Le_Deploy_ssh_user "$Le_Deploy_ssh_user"
 
-   fi
 
-   
 
-   if [ -n "$ACME_DEPLOY_SSH_SERVER" ]; then
 
-     Le_Deploy_ssh_server="$ACME_DEPLOY_SSH_SERVER"
 
-     _savedomainconf Le_Deploy_ssh_server "$Le_Deploy_ssh_server"
 
-   elif [ -z "$Le_Deploy_ssh_server" ]; then
 
-     Le_Deploy_ssh_server="$_cdomain"
 
-   fi
 
-   
 
-   if [ -n "$ACME_DEPLOY_SSH_CMD" ]; then
 
-     Le_Deploy_ssh_cmd="$ACME_DEPLOY_SSH_CMD"
 
-     _savedomainconf Le_Deploy_ssh_cmd "$Le_Deploy_ssh_cmd"
 
-   elif [ -z "$Le_Deploy_ssh_cmd" ]; then
 
-     Le_Deploy_ssh_cmd="ssh"
 
-   fi
 
-   _info "Deploy certificates to remote server $Le_Deploy_ssh_user@$Le_Deploy_ssh_server"
 
-   
 
-   
 
-   if [ -n "$ACME_DEPLOY_SSH_KEYFILE" ]; then
 
-     Le_Deploy_ssh_keyfile="$ACME_DEPLOY_SSH_KEYFILE"
 
-     _savedomainconf Le_Deploy_ssh_keyfile "$Le_Deploy_ssh_keyfile"
 
-   fi
 
-   if [ -n "$Le_Deploy_ssh_keyfile" ]; then
 
-     
 
-     _cmdstr="$_cmdstr cp $Le_Deploy_ssh_keyfile $_backupdir ;"
 
-     
 
-     _cmdstr="$_cmdstr echo \"$(cat "$_ckey")\" > $Le_Deploy_ssh_keyfile ;"
 
-     _info "will copy private key to remote file $Le_Deploy_ssh_keyfile"
 
-   fi
 
-   
 
-   
 
-   if [ -n "$ACME_DEPLOY_SSH_CERTFILE" ]; then
 
-     Le_Deploy_ssh_certfile="$ACME_DEPLOY_SSH_CERTFILE"
 
-     _savedomainconf Le_Deploy_ssh_certfile "$Le_Deploy_ssh_certfile"
 
-   fi
 
-   if [ -n "$Le_Deploy_ssh_certfile" ]; then
 
-     if [ "$Le_Deploy_ssh_certfile" = "$Le_Deploy_ssh_keyfile" ]; then
 
-       
 
-       _pipe=">>"
 
-     else
 
-       
 
-       _cmdstr="$_cmdstr cp $Le_Deploy_ssh_certfile $_backupdir ;"
 
-       _pipe=">"
 
-     fi
 
-     
 
-     _cmdstr="$_cmdstr echo \"$(cat "$_ccert")\" $_pipe $Le_Deploy_ssh_certfile ;"
 
-     _info "will copy certificate to remote file $Le_Deploy_ssh_certfile"
 
-   fi
 
-   
 
-   
 
-   if [ -n "$ACME_DEPLOY_SSH_CAFILE" ]; then
 
-     Le_Deploy_ssh_cafile="$ACME_DEPLOY_SSH_CAFILE"
 
-     _savedomainconf Le_Deploy_ssh_cafile "$Le_Deploy_ssh_cafile"
 
-   fi
 
-   if [ -n "$Le_Deploy_ssh_cafile" ]; then
 
-     if [ "$Le_Deploy_ssh_cafile" = "$Le_Deploy_ssh_keyfile" ] ||
 
-        [ "$Le_Deploy_ssh_cafile" = "$Le_Deploy_ssh_certfile" ]; then
 
-       
 
-       _pipe=">>"
 
-     else
 
-       
 
-       _cmdstr="$_cmdstr cp $Le_Deploy_ssh_cafile $_backupdir ;"
 
-       _pipe=">"
 
-     fi
 
-     
 
-     _cmdstr="$_cmdstr echo \"$(cat "$_cca")\" $_pipe $Le_Deploy_ssh_cafile ;"
 
-     _info "will copy CA file to remote file $Le_Deploy_ssh_cafile"
 
-   fi
 
-   
 
-   
 
-   if [ -n "$ACME_DEPLOY_SSH_FULLCHAIN" ]; then
 
-     Le_Deploy_ssh_fullchain="$ACME_DEPLOY_SSH_FULLCHAIN"
 
-     _savedomainconf Le_Deploy_ssh_fullchain "$Le_Deploy_ssh_fullchain"
 
-   fi
 
-   if [ -n "$Le_Deploy_ssh_fullchain" ]; then
 
-     if [ "$Le_Deploy_ssh_fullchain" = "$Le_Deploy_ssh_keyfile" ] ||
 
-        [ "$Le_Deploy_ssh_fullchain" = "$Le_Deploy_ssh_certfile" ] ||
 
-        [ "$Le_Deploy_ssh_fullchain" = "$Le_Deploy_ssh_cafile" ]; then
 
-       
 
-       _pipe=">>"
 
-     else
 
-       
 
-       _cmdstr="$_cmdstr cp $Le_Deploy_ssh_fullchain $_backupdir ;"
 
-       _pipe=">"
 
-     fi
 
-     
 
-     _cmdstr="$_cmdstr echo \"$(cat "$_cfullchain")\" $_pipe $Le_Deploy_ssh_fullchain ;"
 
-     _info "will copy fullchain to remote file $Le_Deploy_ssh_fullchain"
 
-   fi
 
-   
 
-   
 
-   if [ -n "$ACME_DEPLOY_SSH_REMOTE_CMD" ]; then
 
-     Le_Deploy_ssh_remote_cmd="$ACME_DEPLOY_SSH_REMOTE_CMD"
 
-     _savedomainconf Le_Deploy_ssh_remote_cmd "$Le_Deploy_ssh_remote_cmd"
 
-   fi
 
-   if [ -n "$Le_Deploy_ssh_remote_cmd" ]; then
 
-     _cmdstr="$_cmdstr $Le_Deploy_ssh_remote_cmd ;"
 
-     _info "Will execute remote command $Le_Deploy_ssh_remote_cmd"
 
-   fi
 
-   if [ -z "$_cmdstr" ]; then
 
-     _err "No remote commands to excute. Failed to deploy certificates to remote server"
 
-     return 1
 
-   else
 
-     
 
-     
 
-     _cmdstr="find $_backupprefix* -type d -mtime +180 2>/dev/null | xargs rm -rf ; $_cmdstr"
 
-     
 
-     _cmdstr="mkdir -p $_backupdir ; $_cmdstr"
 
-     _info "Backup of old certificate files will be placed in remote directory $_backupdir"
 
-     _info "Backup directories erased after 180 days."
 
-   fi
 
-   _debug "Remote commands to execute: $_cmdstr"
 
-   _info "Submitting sequence of commands to remote server by ssh"
 
-   
 
-   
 
-   $Le_Deploy_ssh_cmd -T "$Le_Deploy_ssh_user@$Le_Deploy_ssh_server" sh -c "'$_cmdstr'"
 
-   _ret="$?"
 
-   if [ "$_ret" != "0" ]; then
 
-     _err "Error code $_ret returned from $Le_Deploy_ssh_cmd"
 
-   fi
 
-   return $_ret
 
- }
 
 
  |