-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Create Edgemax deploy script. #1226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
b5d168f
0999d10
e0d630d
2b129b9
195e7f5
2a8b806
dd5a5e2
903ae29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#!/bin/bash | ||
|
||
################################################################ | ||
### | ||
### A script to deploy Let's Encrypt certificate | ||
### on Edgemax routers. | ||
### | ||
################################################################ | ||
|
||
#This file name is "edgemax.sh" | ||
#So, here must be a method edgemax_deploy() | ||
#Which will be called by acme.sh to deploy the cert | ||
#returns 0 means success, otherwise error. | ||
|
||
######## Public functions ##################### | ||
atexit() { | ||
#closes CLI session | ||
cli-shell-api teardownSession | ||
_debug EXITCODE: "$1" | ||
return "$1" | ||
} | ||
|
||
#domain keyfile certfile cafile fullchain | ||
edgemax_deploy() { | ||
_cdomain="$1" | ||
_ckey="$2" | ||
_ccert="$3" | ||
_cca="$4" | ||
_cfullchain="$5" | ||
### 'lighttpd_pem' - certificate file configured for your Edgemax GUI | ||
|
||
lighttpd_pem=/config/auth/le-cert.pem | ||
|
||
_info "$(__green "EdgeMax Certificate Path: $lighttpd_pem")" | ||
_debug _cdomain "$_cdomain" | ||
_debug _ckey "$_ckey" | ||
_debug _ccert "$_ccert" | ||
_debug _cca "$_cca" | ||
_debug _cfullchain "$_cfullchain" | ||
_info "Generating PEM file for lighttpd" | ||
sudo sh -c "cat ${_ccert} ${_ckey} > ${lighttpd_pem}" | ||
|
||
_info "$(__green "Checking for Cron Job")" | ||
cronval=$(cli-shell-api returnEffectiveValue system task-scheduler task LetsEncrypt executable path) | ||
if [ "$cronval" != "/config/user-data/acme.sh/acme.sh" ]; then | ||
_info "$(__green "Job not found. Adding")" | ||
vyatta_sbindir="/opt/vyatta/sbin" #overwritten by eval command but needed to pass github checks. | ||
# Obtain session environment | ||
session_env=$(cli-shell-api getSessionEnv $PPID) | ||
eval "$session_env" | ||
|
||
# Setup the session | ||
cli-shell-api setupSession | ||
|
||
# Verify Session Started | ||
cli-shell-api inSession | ||
if [ $? -ne 0 ]; then | ||
_err "Something went wrong starting CLI Session!" | ||
atexit 1 | ||
fi | ||
SET=${vyatta_sbindir}/my_set | ||
COMMIT=${vyatta_sbindir}/my_commit | ||
SAVE=${vyatta_sbindir}/vyatta-save-config.pl | ||
_info "Setting CRON job parameter." | ||
$SET system task-scheduler task LetsEncrypt crontab-spec '39 1 * * *' | ||
$SET system task-scheduler task LetsEncrypt executable arguments '--cron --home /config/user-data/acme.sh --config-home /config/user-data/acme.sh' | ||
$SET system task-scheduler task LetsEncrypt executable path /config/user-data/acme.sh/acme.sh | ||
$COMMIT | ||
$SAVE | ||
else | ||
_info "CRON job already set" | ||
fi | ||
|
||
_info "$(__green "Checking EdgeMax Config for SSL Settings: $lighttpd_pem")" | ||
vals=$(cli-shell-api returnEffectiveValue service gui cert-file) | ||
certfile=$vals | ||
if [ "$lighttpd_pem" != "$certfile" ]; then | ||
_debug "Current Edgemax Certfile" "$certfile" | ||
_info "Certfile is not set to $lighttpd_pem" | ||
|
||
vyatta_sbindir="/opt/vyatta/sbin" #overwritten by eval command but needed to pass github checks. | ||
# Obtain session environment | ||
session_env=$(cli-shell-api getSessionEnv $PPID) | ||
eval "$session_env" | ||
|
||
# Setup the session | ||
cli-shell-api setupSession | ||
|
||
# Verify Session Started | ||
cli-shell-api inSession | ||
if [ $? -ne 0 ]; then | ||
_err "Something went wrong starting CLI Session!" | ||
atexit 1 | ||
fi | ||
SET=${vyatta_sbindir}/my_set | ||
COMMIT=${vyatta_sbindir}/my_commit | ||
SAVE=${vyatta_sbindir}/vyatta-save-config.pl | ||
_info "Setting Certificate parameter." | ||
$SET service gui cert-file /config/auth/le-cert.pem | ||
$COMMIT | ||
$SAVE | ||
else | ||
_info "EdgeMax cert-file already set to $lighttpd_pem" | ||
fi | ||
_info Restarting lighttpd | ||
sudo kill -SIGTERM "$(cat /var/run/lighttpd.pid)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On these particular devices (edgemax), in their build of linux sudo does not require a password. It is however required to restart the web service that the certificate is being installed to though i'd rather all the other tasks the script does not run as root. I will double verify that I can't reboot the webserver as the standard user but I am fairly confident that sudo is required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have checked and I cannot reboot the web service (needed for deployment) without root privileges but for installation and execution of tasks/cronjobs etc ideally on these devices i'd like them to be user level. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the sudo requires inputing password, the cronjob will be broken. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the sudo does not require inputting password |
||
sudo /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf | ||
|
||
atexit 0 | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change the shebang to the same as the others'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused on this request. When I look at all of the other deploy scripts, they are just
#!/bin/bash
Same as this one.
What do you want me to change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/Neilpang/acme.sh/blob/master/deploy/vsftpd.sh#L1