diff --git a/README.md b/README.md index 4ae4954..68df509 100644 --- a/README.md +++ b/README.md @@ -177,11 +177,8 @@ Note: Using DNS validation is now working successfully for issuing certificate ## Automating updates -I use 2 seperate crons, so my crontab looks like +I use the following cron ``` -23 5 * * * /root/scripts/getssl -u -q -47 5 * * * /root/scripts/getssl -a -q +23 5 * * * /root/scripts/getssl -u -a -q ``` -The first cron will update getssl if there are any more recent versions available (the -u flag). I use the -q flag so it only outputs and emails me if it has upgraded. - -The second cron runs though all certificates (the -a flag) and uutomatically renews any certificates thatare due for renewal. I use the -q flag so that it only outputs and emails me if any certificates were updated, or there was an error / issue. \ No newline at end of file +The cron will update getssl if there are any more recent versions available (the -u flag). The -a flag automatically renews any certificates that are due for renewal. I use the -q flag so that it only outputs and emails me if any certificates were updated, or there was an error / issue. \ No newline at end of file diff --git a/getssl b/getssl index 08bc6d4..d9cd03f 100755 --- a/getssl +++ b/getssl @@ -59,10 +59,13 @@ # 2016-05-30 Add version check to see if there is a more recent version of getssl (0.41) # 2016-05-30 Add [-u|--upgrade] option to automatically upgrade getssl (0.42) # 2016-05-30 Added backup when auto-upgrading (0.43) +# 2016-05-30 Improvements to auto-upgrade (0.44) # --------------------------------------------------------------------------- PROGNAME=${0##*/} -VERSION="0.43" +VERSION="0.44" + +ORIGCMD="$0 $*" # defaults CA="https://acme-staging.api.letsencrypt.org" @@ -153,32 +156,21 @@ check_upgrade() { debug "Most recent version is ${latestversion}" # use a default of 0 for cases where the latest code has not been obtained. if [ "${latestvdec:-0}" -gt "$localvdec" ]; then - info "" - info "A more recent version (v${latestversion}) of getssl is available, please update" - info "the easiest way may be to use the -u or --upgrade option on getssl, or" - info "git pull (if using git) or " - info "curl --silent https://raw.githubusercontent.com/srvrco/getssl/master/getssl > $0" - info "" - fi -} - -self_upgrade () { - latestcode=$(curl --silent https://raw.githubusercontent.com/srvrco/getssl/master/getssl) - latestversion=$(echo "$latestcode" | grep VERSION= | head -1| awk -F'"' '{print $2}') - latestvdec=$(echo "$latestversion"| tr -d '.') - localvdec=$(echo "$VERSION"| tr -d '.' ) - # use a default of 0 for cases where the latest code has not been obtained. - if [ "${latestvdec:-0}" -gt "$localvdec" ]; then - temp_upgrade="$(mktemp)" - echo "$latestcode" > "$temp_upgrade" - install "$0" "${0}.v${VERSION}" - install "$temp_upgrade" "$0" - rm -f "$temp_upgrade" - info "Updated getssl from v${VERSION} to v${latestversion}" - graceful_exit - else - debug "current version is up-to-date" - graceful_exit + if [ ${_UPGRADE} -eq 1 ]; then + temp_upgrade="$(mktemp)" + echo "$latestcode" > "$temp_upgrade" + install "$0" "${0}.v${VERSION}" + install "$temp_upgrade" "$0" + rm -f "$temp_upgrade" + info "Updated getssl from v${VERSION} to v${latestversion}" + eval "$ORIGCMD" + graceful_exit + else + info "" + info "A more recent version (v${latestversion}) of getssl is available, please update" + info "the easiest way is to use the -u or --upgrade flag" + info "" + fi fi } @@ -590,12 +582,8 @@ _requires grep _requires awk _requires tr -# if --upgrade option is used, then attempt self-upgrade. -if [ ${_UPGRADE} -eq 1 ]; then - self_upgrade -else # perform a check and inform user if upgrade is available. - check_upgrade -fi +# Check if upgrades are available +check_upgrade # if "-a" option then check other parameters and create run for each domain. if [ ${_CHECK_ALL} -eq 1 ]; then