Skip to content

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

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions deploy/edgemax.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/bin/bash
Copy link
Member

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'

Copy link
Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


################################################################
###
### 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)"
Copy link
Member

@Neilpang Neilpang Feb 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do the sudo need to input password ?
do not use sudo in the script.
if you really want to do something as root, install and run acme.sh as root. do not use sudo in your script.

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the sudo requires inputing password, the cronjob will be broken.
Never never never use sudo.

Copy link
Author

Choose a reason for hiding this comment

The 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

}