Created
June 25, 2017 06:46
-
-
Save anthonyeden/e5d2f63a27505c54c00b33982a7e9914 to your computer and use it in GitHub Desktop.
Icecast: Pull Configuration from S3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This script downloads your Icecast XML script from AWS S3, compares it for changes, and reloads Icecast if changes have been found | |
# Written by Anthony Eden (http://mediarealm.com.au/) | |
file="icecast.xml" | |
bucket="BUCKET-NAME-GOES-HERE" | |
s3Key="KEY-GOES-HERE" | |
s3Secret="SECRET-GOES-HERE" | |
resource="/${bucket}/${file}" | |
contentType="application/xml" | |
dateValue="`date +'%a, %d %b %Y %H:%M:%S %z'`" | |
stringToSign="GET\n\n${contentType}\n${dateValue}\n${resource}" | |
signature=`/bin/echo -en "$stringToSign" | openssl sha1 -hmac ${s3Secret} -binary | base64` | |
curl -H "Host: ${bucket}.s3.amazonaws.com" \ | |
-H "Date: ${dateValue}" \ | |
-H "Content-Type: ${contentType}" \ | |
-H "Authorization: AWS ${s3Key}:${signature}" \ | |
https://${bucket}.s3.amazonaws.com/${file} \ | |
-o $file | |
diff --brief icecast.xml /etc/icecast2/icecast.xml >/dev/null | |
comp_value=$? | |
if [ $comp_value -eq 1 ] | |
then | |
# These files are different - update live config | |
echo "The new file is different. Copying to the live icecast directory" | |
cp /etc/icecast2/icecast.xml /etc/icecast2/icecast-backup.xml | |
cp icecast.xml /etc/icecast2/icecast.xml | |
# Restart icecast (soft restart, respecting existing connections) | |
/etc/init.d/icecast2 reload | |
else | |
# No change - leave as-is | |
echo "The new file is unchanged. Not moving." | |
Fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment