Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Icecast: Pull Configuration from S3
#!/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
You can’t perform that action at this time.