expire-sites/expire-sites

57 lines
1.2 KiB
Bash
Executable File

#!/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: ' ${APACHEDIR} >&2
exit 1
fi
# Update repository
cd ${WORKDIR}
echo 'Updating repository'
git pull
# Ensure there are no uncommitted changes
cd ${APACHEDIR}
echo 'Checking for uncommited changes'
git diff --name-only --exit-code > /dev/null
if [ $? -ne 0 ]; then
echo "There are uncommited changes in ${APACHEDIR}." >&2
echo "Sincerely yours," >&2
echo "$(hostname)" >&2
exit 1
fi
# Generate updated configuration
cd ${WORKDIR}
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