123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #!/usr/bin/env sh
- routeros_deploy() {
- _cdomain="$1"
- _ckey="$2"
- _ccert="$3"
- _cca="$4"
- _cfullchain="$5"
- _debug _cdomain "$_cdomain"
- _debug _ckey "$_ckey"
- _debug _ccert "$_ccert"
- _debug _cca "$_cca"
- _debug _cfullchain "$_cfullchain"
- if [ -z "$ROUTER_OS_HOST" ]; then
- _debug "Using _cdomain as ROUTER_OS_HOST, please set if not correct."
- ROUTER_OS_HOST="$_cdomain"
- fi
- if [ -z "$ROUTER_OS_USERNAME" ]; then
- _err "Need to set the env variable ROUTER_OS_USERNAME"
- return 1
- fi
- if [ -z "$ROUTER_OS_ADDITIONAL_SERVICES" ]; then
- _debug "Not enabling additional services"
- ROUTER_OS_ADDITIONAL_SERVICES=""
- fi
- _info "Trying to push key '$_ckey' to router"
- scp "$_ckey" "$ROUTER_OS_USERNAME@$ROUTER_OS_HOST:$_cdomain.key"
- _info "Trying to push cert '$_cfullchain' to router"
- scp "$_cfullchain" "$ROUTER_OS_USERNAME@$ROUTER_OS_HOST:$_cdomain.cer"
- DEPLOY_SCRIPT_CMD="/system script add name=\"LE Cert Deploy - $_cdomain\" owner=admin policy=ftp,read,write,password,sensitive
- source=\"## generated by routeros deploy script in acme.sh
- \n/certificate remove [ find name=$_cdomain.cer_0 ]
- \n/certificate remove [ find name=$_cdomain.cer_1 ]
- \ndelay 1
- \n/certificate import file-name=$_cdomain.cer passphrase=\\\"\\\"
- \n/certificate import file-name=$_cdomain.key passphrase=\\\"\\\"
- \ndelay 1
- \n/file remove $_cdomain.cer
- \n/file remove $_cdomain.key
- \ndelay 2
- \n/ip service set www-ssl certificate=$_cdomain.cer_0
- \n$ROUTER_OS_ADDITIONAL_SERVICES
- \n\"
- "
-
- ssh "$ROUTER_OS_USERNAME@$ROUTER_OS_HOST" "$DEPLOY_SCRIPT_CMD"
-
- ssh "$ROUTER_OS_USERNAME@$ROUTER_OS_HOST" "/system script run \"LE Cert Deploy - $_cdomain\""
-
- ssh "$ROUTER_OS_USERNAME@$ROUTER_OS_HOST" "/system script remove \"LE Cert Deploy - $_cdomain\""
- return 0
- }
|