Do not commit if there are uncommited changes in apache config directory
[public/expire-sites.git] / expire-sites
1 #!/bin/bash
2
3 # Configuration
4 WORKDIR=/opt/expire-sites
5 APACHEDIR=/etc/apache2
6 CONFIGFILE=${APACHEDIR}/conf-available/disable-expired-site.conf
7
8 # Check
9 if [ ! -e ${WORKDIR} ]; then
10    echo 'Unable to find work directory: ' ${WORKDIR} >&2
11    exit 1
12 fi
13
14 if [ ! -e ${APACHEDIR} ]; then
15    echo 'Unable to find Apache configuration directory: ' ${APACHEDIR} >&2
16    exit 1
17 fi
18
19 # Setup
20 cd ${WORKDIR}
21
22 echo 'Updating repository'
23 git pull
24
25 # Generate updated configuration
26 echo 'Generating new configuration'
27 ./generate-expire-config > ${CONFIGFILE}
28
29 # Check if file has changed
30 cd ${APACHEDIR}
31
32 echo 'Checking for changes'
33 git diff --name-only --exit-code ${CONFIGFILE} > /dev/null
34
35 if [ $? -ne 0 ]; then
36    echo 'Checking for uncommited changes'
37    git diff --name-only --exit-code > /dev/null
38
39    if [ $? -ne 0 ]; then
40       echo "There are uncommited changes in ${APACHEDIR}." >&2
41       echo "Sincerely yours," >&2
42       echo "$(hostname)" >&2
43       exit 1
44    fi
45
46    echo 'Changes detected: Commiting updated configuration'
47    git add ${CONFIGFILE}
48    git commit -m '[CRON] Updated list of expired sites'
49
50    echo 'Reloading apache'
51    service apache2 reload
52 else
53    echo 'No changes detected'
54 fi