Skip to content

Instantly share code, notes, and snippets.

@erbanku
Last active March 16, 2022 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erbanku/bbbaad65ce840a1dd2c8581e5ec4c3b0 to your computer and use it in GitHub Desktop.
Save erbanku/bbbaad65ce840a1dd2c8581e5ec4c3b0 to your computer and use it in GitHub Desktop.
#!/bin/bash
screen -wipe
cd /root
screen -h 9999 -dmS "ssl-renew"; sleep 0.1
screen -S "ssl-renew" -p 0 -X stuff $"./ssl-renew.sh\n"
certbot certonly --standalone -d dukelec.com -d www.dukelec.com -d d-l.io -d www.d-l.io -d blog.dukelec.com -d blog.d-l.io -d e.d-l.io
#!/bin/bash
#
# Software License Agreement (MIT License)
#
# Author: Duke Fong <d(at)d-l.io>
#
# Create ssl-renew.last template:
# echo "$(date +'%Y-%m-%d %H:%M')" > ssl-renew.last
#
set -e
PROGRESS_BAR_WIDTH=50
draw_progress_bar() {
# arguments: current value, max value, unit (optional)
local __value=$1
local __max=$2
local __unit=${3:-""}
if (( $__max < 1 )); then __max=1; fi
local __percentage=$(( 100 - ($__max*100 - $__value*100) / $__max ))
local __num_bar=$(( $__percentage * $PROGRESS_BAR_WIDTH / 100 ))
printf "["
for b in $(seq 1 $__num_bar); do printf "#"; done
for s in $(seq 1 $(( $PROGRESS_BAR_WIDTH - $__num_bar ))); do printf " "; done
printf "] $__percentage%% ($__value / $__max $__unit)\r"
}
renew=$((60*60*24*80)) # renew after 80 day
last=$(tail -n 1 ssl-renew.last)
last=$(date -d "$last" +%s)
next=$((last+renew))
echo "last renew at: $last | $(date --date @$last +'%Y-%m-%d %H:%M')"
echo "next renew at: $next | $(date --date @$next +'%Y-%m-%d %H:%M')"
printf "\n"
while true; do
cur=$(date +%s)
offset=$((cur-last))
draw_progress_bar $offset $renew s
if (( cur > next )); then
printf "\n" # end progress bar
last=$(date +%s)
next=$((last+renew))
echo "renew @ $last | $(date --date @$last +'%Y-%m-%d %H:%M') ..."
echo "$(date --date @$last +'%Y-%m-%d %H:%M')" >> ssl-renew.last
echo "stop apache..."
/etc/init.d/apache2 stop
echo "certbot renew..."
certbot renew -n
echo "start apache..."
/etc/init.d/apache2 start
sync
echo "done, next renew at: $next | $(date --date @$next +'%Y-%m-%d %H:%M')"
printf "\n"
fi
sleep 5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment