Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
45932310
Commit
45932310
authored
Feb 28, 2020
by
David Kerr
Browse files
Merge branch 'ssh-deploy' of
https://github.com/dkerr64/acme.sh
into ssh-deploy
# Conflicts: # deploy/ssh.sh
parents
04771e5a
f73a4944
Changes
1
Hide whitespace changes
Inline
Side-by-side
deploy/ssh.sh
View file @
45932310
...
...
@@ -21,6 +21,7 @@
# export DEPLOY_SSH_FULLCHAIN=""
# export DEPLOY_SSH_REMOTE_CMD="/etc/init.d/stunnel.sh restart"
# export DEPLOY_SSH_BACKUP="" # yes or no, default to yes
# export DEPLOY_SSH_BATCH_MODE="yes" # yes or no, default to yes
#
######## Public functions #####################
...
...
@@ -78,12 +79,44 @@ ssh_deploy() {
# BACKUP is optional. If not provided then default to yes
if
[
"
$DEPLOY_SSH_BACKUP
"
=
"no"
]
;
then
Le_Deploy_ssh_backup
=
"no"
elif
[
-z
"
$Le_Deploy_ssh_backup
"
]
;
then
elif
[
-z
"
$Le_Deploy_ssh_backup
"
]
||
[
"
$DEPLOY_SSH_BACKUP
"
=
"yes"
]
;
then
Le_Deploy_ssh_backup
=
"yes"
fi
_savedomainconf Le_Deploy_ssh_backup
"
$Le_Deploy_ssh_backup
"
# BATCH_MODE is optional. If not provided then default to yes
if
[
"
$DEPLOY_SSH_BATCH_MODE
"
=
"no"
]
;
then
Le_Deploy_ssh_batch_mode
=
"no"
elif
[
-z
"
$Le_Deploy_ssh_batch_mode
"
]
||
[
"
$DEPLOY_SSH_BATCH_MODE
"
=
"yes"
]
;
then
Le_Deploy_ssh_batch_mode
=
"yes"
fi
_savedomainconf Le_Deploy_ssh_batch_mode
"
$Le_Deploy_ssh_batch_mode
"
_info
"Deploy certificates to remote server
$Le_Deploy_ssh_user
@
$Le_Deploy_ssh_server
"
if
[
"
$Le_Deploy_ssh_batch_mode
"
=
"yes"
]
;
then
_info
"Using BATCH MODE... Multiple commands sent in single call to remote host"
else
_info
"Commands sent individually in multiple calls to remote host"
fi
if
[
"
$Le_Deploy_ssh_backup
"
=
"yes"
]
;
then
# run cleanup on the backup directory, erase all older
# than 180 days (15552000 seconds).
_cmdstr
=
"{ now=
\"\$
(date -u +%s)
\"
; for fn in
$_backupprefix
*;
\
do if [ -d
\"\$
fn
\"
] && [
\"\$
(expr
\$
now -
\$
(date -ur
\$
fn +%s) )
\"
-ge
\"
15552000
\"
];
\
then rm -rf
\"\$
fn
\"
; echo
\"
Backup
\$
fn deleted as older than 180 days
\"
; fi; done; };
$_cmdstr
"
# Alternate version of above... _cmdstr="find $_backupprefix* -type d -mtime +180 2>/dev/null | xargs rm -rf; $_cmdstr"
# Create our backup directory for overwritten cert files.
_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."
if
[
"
$Le_Deploy_ssh_batch_mode
"
=
"no"
]
;
then
if
!
_ssh_remote_cmd
"
$_cmdstr
"
;
then
return
$_err_code
fi
_cmdstr
=
""
fi
fi
# KEYFILE is optional.
# If provided then private key will be copied to provided filename.
...
...
@@ -99,6 +132,12 @@ ssh_deploy() {
# copy new certificate into file.
_cmdstr
=
"
$_cmdstr
echo
\"
$(
cat
"
$_ckey
"
)
\"
>
$Le_Deploy_ssh_keyfile
;"
_info
"will copy private key to remote file
$Le_Deploy_ssh_keyfile
"
if
[
"
$Le_Deploy_ssh_batch_mode
"
=
"no"
]
;
then
if
!
_ssh_remote_cmd
"
$_cmdstr
"
;
then
return
$_err_code
fi
_cmdstr
=
""
fi
fi
# CERTFILE is optional.
...
...
@@ -119,6 +158,12 @@ ssh_deploy() {
# copy new certificate into file.
_cmdstr
=
"
$_cmdstr
echo
\"
$(
cat
"
$_ccert
"
)
\"
$_pipe
$Le_Deploy_ssh_certfile
;"
_info
"will copy certificate to remote file
$Le_Deploy_ssh_certfile
"
if
[
"
$Le_Deploy_ssh_batch_mode
"
=
"no"
]
;
then
if
!
_ssh_remote_cmd
"
$_cmdstr
"
;
then
return
$_err_code
fi
_cmdstr
=
""
fi
fi
# CAFILE is optional.
...
...
@@ -140,6 +185,12 @@ ssh_deploy() {
# copy new certificate into file.
_cmdstr
=
"
$_cmdstr
echo
\"
$(
cat
"
$_cca
"
)
\"
$_pipe
$Le_Deploy_ssh_cafile
;"
_info
"will copy CA file to remote file
$Le_Deploy_ssh_cafile
"
if
[
"
$Le_Deploy_ssh_batch_mode
"
=
"no"
]
;
then
if
!
_ssh_remote_cmd
"
$_cmdstr
"
;
then
return
$_err_code
fi
_cmdstr
=
""
fi
fi
# FULLCHAIN is optional.
...
...
@@ -162,6 +213,12 @@ ssh_deploy() {
# copy new certificate into file.
_cmdstr
=
"
$_cmdstr
echo
\"
$(
cat
"
$_cfullchain
"
)
\"
$_pipe
$Le_Deploy_ssh_fullchain
;"
_info
"will copy fullchain to remote file
$Le_Deploy_ssh_fullchain
"
if
[
"
$Le_Deploy_ssh_batch_mode
"
=
"no"
]
;
then
if
!
_ssh_remote_cmd
"
$_cmdstr
"
;
then
return
$_err_code
fi
_cmdstr
=
""
fi
fi
# REMOTE_CMD is optional.
...
...
@@ -173,42 +230,35 @@ ssh_deploy() {
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
"
if
[
"
$Le_Deploy_ssh_batch_mode
"
=
"no"
]
;
then
if
!
_ssh_remote_cmd
"
$_cmdstr
"
;
then
return
$_err_code
fi
_cmdstr
=
""
fi
fi
if
[
-z
"
$_cmdstr
"
]
;
then
_err
"No remote commands to excute. Failed to deploy certificates to remote server"
return
1
elif
[
"
$Le_Deploy_ssh_backup
"
=
"yes"
]
;
then
# run cleanup on the backup directory, erase all older
# than 180 days (15552000 seconds).
_cmdstr
=
"{ now=
\"\$
(date -u +%s)
\"
; for fn in
$_backupprefix
*;
\
do if [ -d
\"\$
fn
\"
] && [
\"\$
(expr
\$
now -
\$
(date -ur
\$
fn +%s) )
\"
-ge
\"
15552000
\"
];
\
then rm -rf
\"\$
fn
\"
; echo
\"
Backup
\$
fn deleted as older than 180 days
\"
; fi; done; };
$_cmdstr
"
# Alternate version of above... _cmdstr="find $_backupprefix* -type d -mtime +180 2>/dev/null | xargs rm -rf; $_cmdstr"
# Create our backup directory for overwritten cert files.
_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
if
!
_ssh_remote_cmd
"
$_cmdstr
"
;
then
return
$_err_code
# if running as batch mode then all commands sent in a single SSH call now...
if
[
-n
"
$_cmdstr
"
]
;
then
if
!
_ssh_remote_cmd
"
$_cmdstr
"
;
then
return
$_err_code
fi
fi
return
0
}
#cmd
_ssh_remote_cmd
()
{
_cmd
=
"
$1
"
_secure_debug
"Remote commands to execute:
$_cmd
"
_info
"Submitting sequence of commands to remote server by
$Le_Deploy_ssh_cmd
"
_info
"Submitting sequence of commands to remote server by
ssh
"
# quotations in bash cmd below intended. Squash travis spellcheck error
# shellcheck disable=SC2029
$Le_Deploy_ssh_cmd
"
$Le_Deploy_ssh_user
@
$Le_Deploy_ssh_server
"
sh
-c
"'
$_cmd
'"
_err_code
=
"
$?
"
if
[
"
$_err_code
"
!=
"0"
]
;
then
_err
"Error code
$_err_code
returned from
$Le_Deploy_ssh_cmd
"
_err
"Error code
$_err_code
returned from
ssh
"
fi
return
$_err_code
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment