Skip to content

Instantly share code, notes, and snippets.

@joeneldeasis
Last active December 2, 2018 22:24
Show Gist options
  • Save joeneldeasis/02a3bc049d277aa49638956e608ec8c9 to your computer and use it in GitHub Desktop.
Save joeneldeasis/02a3bc049d277aa49638956e608ec8c9 to your computer and use it in GitHub Desktop.
Script for updating certbot dependencies on AWS Linux AMI
#!/bin/bash
### Change the permission of certscript.sh: chmod +x /path/to/certscript.sh
### Add this script to root user's cron: 0 0 1 * * sh /path/to/certscript.sh
user=$(whoami)
certbot_dir="/usr/bin"
if [[ $user != 'root' ]]; then
echo "[*] Please run this script as root user!"
exit 1
elif [[ -e $certbot_dir/certbot-auto ]]; then
echo "[*] Certbot found, updating certbot dependencies"
echo "--------------------------------------------------------"
date >> certscript.log
unset PYTHON_INSTALL_LAYOUT >> certscript.log
/opt/eff.org/certbot/venv/local/bin/pip install --upgrade certbot >> certscript.log
echo "[*] Performing certificate renewal on these domains"
ls -1 /etc/letsencrypt/live/
certbot-auto renew --pre-hook "service nginx stop" --post-hook "service nginx start" --debug >> certscript.log
if [[ ! $? -eq 0 ]]; then
echo "Error occured while renewing the certificates"
rm -rf /opt/eff.org
certbot-auto renew --pre-hook "service nginx stop" --post-hook "service nginx start" --debug >> certscript.log
service nginx restart
if [[ $? -eq 0 ]]; then
echo "Successfully renewed all the certificates"
ls -1 /etc/letsencrypt/live/
service nginx restart
fi
elif [[ $? -eq 0 ]]; then
echo "Successfully renewed all the certificates"
service nginx restart
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment