#!/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