Cron update
authorZachary Seguin <ztseguin@csclub.uwaterloo.ca>
Tue, 2 Feb 2016 04:37:13 +0000 (23:37 -0500)
committerZachary Seguin <ztseguin@csclub.uwaterloo.ca>
Tue, 2 Feb 2016 04:37:13 +0000 (23:37 -0500)
expire-sites [new file with mode: 0755]

diff --git a/expire-sites b/expire-sites
new file mode 100755 (executable)
index 0000000..c068316
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+# Configuration
+WORKDIR=/opt/expire-sites
+APACHEDIR=/etc/apache2
+CONFIGFILE=${APACHEDIR}/conf-available/disable-expired-site.conf
+
+# Check
+if [ ! -e ${WORKDIR} ]; then
+   echo 'Unable to find work directory: ' ${WORKDIR} >&2
+   exit 1
+fi
+
+if [ ! -e ${APACHEDIR} ]; then
+   echo 'Unable to find apache configuration directory: ' ${WORKDIR} >&2
+   exit 1
+fi
+
+# Setup
+cd ${WORKDIR}
+
+echo 'Updating repository'
+git pull
+
+# Generate updated configuration
+echo 'Generating new configuration'
+./generate-expire-config > ${CONFIGFILE}
+
+# Check if file has changed
+cd ${APACHEDIR}
+
+echo 'Checking for changes'
+git diff --name-only --exit-code ${CONFIGFILE} > /dev/null
+
+if [ $? -ne 0 ]; then
+   echo 'Changes detected: Commiting updated configuration'
+   git add ${CONFIGFILE}
+   git commit -m '[CRON] Updated list of expired sites'
+
+   echo 'Reloading apache'
+   service apache2 reload
+else
+   echo 'No changes detected'
+fi