Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
6fb8c0ec
Unverified
Commit
6fb8c0ec
authored
Mar 20, 2022
by
neil
Committed by
GitHub
Mar 20, 2022
Browse files
Merge pull request #3989 from abiessmann/deploy_routeros_handle_remote_errors
deploy/routeros: handle errors
parents
07cedc55
3411b736
Changes
1
Show whitespace changes
Inline
Side-by-side
deploy/routeros.sh
View file @
6fb8c0ec
...
@@ -70,6 +70,7 @@ routeros_deploy() {
...
@@ -70,6 +70,7 @@ routeros_deploy() {
_ccert
=
"
$3
"
_ccert
=
"
$3
"
_cca
=
"
$4
"
_cca
=
"
$4
"
_cfullchain
=
"
$5
"
_cfullchain
=
"
$5
"
_err_code
=
0
_debug _cdomain
"
$_cdomain
"
_debug _cdomain
"
$_cdomain
"
_debug _ckey
"
$_ckey
"
_debug _ckey
"
$_ckey
"
...
@@ -126,10 +127,16 @@ routeros_deploy() {
...
@@ -126,10 +127,16 @@ routeros_deploy() {
_savedeployconf ROUTER_OS_SCP_CMD
"
$ROUTER_OS_SCP_CMD
"
_savedeployconf ROUTER_OS_SCP_CMD
"
$ROUTER_OS_SCP_CMD
"
_savedeployconf ROUTER_OS_ADDITIONAL_SERVICES
"
$ROUTER_OS_ADDITIONAL_SERVICES
"
_savedeployconf ROUTER_OS_ADDITIONAL_SERVICES
"
$ROUTER_OS_ADDITIONAL_SERVICES
"
_info
"Trying to push key '
$_ckey
' to router"
# push key to routeros
$ROUTER_OS_SCP_CMD
"
$_ckey
"
"
$ROUTER_OS_USERNAME
@
$ROUTER_OS_HOST
:
$_cdomain
.key"
if
!
_scp_certificate
"
$_ckey
"
"
$ROUTER_OS_USERNAME
@
$ROUTER_OS_HOST
:
$_cdomain
.key"
;
then
_info
"Trying to push cert '
$_cfullchain
' to router"
return
$_err_code
$ROUTER_OS_SCP_CMD
"
$_cfullchain
"
"
$ROUTER_OS_USERNAME
@
$ROUTER_OS_HOST
:
$_cdomain
.cer"
fi
# push certificate chain to routeros
if
!
_scp_certificate
"
$_cfullchain
"
"
$ROUTER_OS_USERNAME
@
$ROUTER_OS_HOST
:
$_cdomain
.cer"
;
then
return
$_err_code
fi
DEPLOY_SCRIPT_CMD
=
"/system script add name=
\"
LE Cert Deploy -
$_cdomain
\"
owner=
$ROUTER_OS_USERNAME
\
DEPLOY_SCRIPT_CMD
=
"/system script add name=
\"
LE Cert Deploy -
$_cdomain
\"
owner=
$ROUTER_OS_USERNAME
\
comment=
\"
generated by routeros deploy script in acme.sh
\"
\
comment=
\"
generated by routeros deploy script in acme.sh
\"
\
source=
\"
/certificate remove [ find name=
$_cdomain
.cer_0 ];
\
source=
\"
/certificate remove [ find name=
$_cdomain
.cer_0 ];
\
...
@@ -146,14 +153,51 @@ source=\"/certificate remove [ find name=$_cdomain.cer_0 ];\
...
@@ -146,14 +153,51 @@ source=\"/certificate remove [ find name=$_cdomain.cer_0 ];\
\n
$ROUTER_OS_ADDITIONAL_SERVICES
;
\
\n
$ROUTER_OS_ADDITIONAL_SERVICES
;
\
\n\"
\n\"
"
"
_debug DEPLOY_SCRIPT_CMD
"
${
DEPLOY_SCRIPT_CMD
}
"
# shellcheck disable=SC2029
if
!
_ssh_remote_cmd
"
$DEPLOY_SCRIPT_CMD
"
;
then
$ROUTER_OS_SSH_CMD
"
$ROUTER_OS_USERNAME
@
$ROUTER_OS_HOST
"
"
$DEPLOY_SCRIPT_CMD
"
return
$_err_code
# shellcheck disable=SC2029
fi
$ROUTER_OS_SSH_CMD
"
$ROUTER_OS_USERNAME
@
$ROUTER_OS_HOST
"
"/system script run
\"
LE Cert Deploy -
$_cdomain
\"
"
# shellcheck disable=SC2029
if
!
_ssh_remote_cmd
"/system script run
\"
LE Cert Deploy -
$_cdomain
\"
"
;
then
$ROUTER_OS_SSH_CMD
"
$ROUTER_OS_USERNAME
@
$ROUTER_OS_HOST
"
"/system script remove
\"
LE Cert Deploy -
$_cdomain
\"
"
return
$_err_code
fi
if
!
_ssh_remote_cmd
"/system script remove
\"
LE Cert Deploy -
$_cdomain
\"
"
;
then
return
$_err_code
fi
return
0
return
0
}
}
# inspired by deploy/ssh.sh
_ssh_remote_cmd
()
{
_cmd
=
"
$1
"
_secure_debug
"Remote commands to execute:
$_cmd
"
_info
"Submitting sequence of commands to routeros"
# quotations in bash cmd below intended. Squash travis spellcheck error
# shellcheck disable=SC2029
$ROUTER_OS_SSH_CMD
"
$ROUTER_OS_USERNAME
@
$ROUTER_OS_HOST
"
"
$_cmd
"
_err_code
=
"
$?
"
if
[
"
$_err_code
"
!=
"0"
]
;
then
_err
"Error code
$_err_code
returned from routeros"
fi
return
$_err_code
}
_scp_certificate
()
{
_src
=
"
$1
"
_dst
=
"
$2
"
_secure_debug
"scp '
$_src
' to '
$_dst
'"
_info
"Push key '
$_src
' to routeros"
$ROUTER_OS_SCP_CMD
"
$_src
"
"
$_dst
"
_err_code
=
"
$?
"
if
[
"
$_err_code
"
!=
"0"
]
;
then
_err
"Error code
$_err_code
returned from scp"
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