Skip to content

Instantly share code, notes, and snippets.

@ryansully
Last active March 16, 2024 18:38
Show Gist options
  • Save ryansully/3b65b59a0386e699acfc5ca7827d5b64 to your computer and use it in GitHub Desktop.
Save ryansully/3b65b59a0386e699acfc5ca7827d5b64 to your computer and use it in GitHub Desktop.
Automatically copies Synology's Let's Encrypt certificate files to SickRage so HTTPS/SSL can be enabled
#!/bin/sh
# CONFIGURATION
script_folder=/volume1/scripts
# SickRage folder
sickrage_folder=/usr/local/sickbeard-custom/var/SickBeard
# Synology's default Let's Encrypt folder
letsencrypt_cert_folder=/usr/syno/etc/certificate/system/default
# renew timestamp
renew_timestamp=renew_sickrage_timestamp
# DO NOT CHANGE BELOW UNLESS YOU'RE A NINJA
copy_certs=false
current_date=`date +"%s"`
current_certificate_date=`openssl x509 -enddate -noout -in $letsencrypt_cert_folder/cert.pem | cut -d'=' -f2`
current_certificate_timestamp=`date -d "$current_certificate_date" +"%s"`
# check if the renew_timestamp file exists
if [ ! -f $script_folder/$renew_timestamp ]; then
# create new timestamp file
echo "Generate timestamp for the current renew date... "
echo $current_certificate_timestamp > $script_folder/$renew_timestamp
chmod +rw $script_folder/$renew_timestamp
chown admin:users $script_folder/$renew_timestamp
# copy certs to SickRage folder
copy_certs=true
else
renew_date=`cat $script_folder/$renew_timestamp`
# check if it is necessary to renew the certificate or not
if expr "$current_date" ">" "$renew_date" > /dev/null; then
echo "Certificate has been renewed..."
copy_certs=true
# update timestamp in the file
echo $current_certificate_timestamp > $script_folder/$renew_timestamp
else
echo "It is not necessary to copy certificate files, abort."
exit 0
fi
fi
# copy certs and restart SickRage
if expr "$copy_certs" "=" "true" > /dev/null; then
echo "Copying certificate files to SickRage folder..."
cp $letsencrypt_cert_folder/cert.pem $sickrage_folder/server.crt
cp $letsencrypt_cert_folder/privkey.pem $sickrage_folder/server.key
chmod +r $sickrage_folder/server*
chown admin:users $sickrage_folder/server*
echo "Restarting SickRage..."
sh /var/packages/sickbeard-custom/scripts/start-stop-status stop
sh /var/packages/sickbeard-custom/scripts/start-stop-status start
echo "Done."
fi
@ryansully
Copy link
Author

  1. Copy this script to /volume1/scripts/, or wherever you want (just be sure to update the script with the new location).
  2. In Synology DSM, create a task in Task Scheduler (Control Panel -> Task Scheduler -> Create -> Scheduled Task -> User-defined script) that runs this script daily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment