summaryrefslogtreecommitdiff
path: root/web-server/home-wwwcvs/update-symlinks.sh
blob: c733e12ccb18912ec6416764d643a81e5dcb2421 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash

if [ -e /var/tmp/update-symlinks.pid ]; then
    # See if the process is still running
    pid=`cat /var/tmp/update-symlinks.pid`
    if [ -e /proc/$pid ]; then
  # send a warning mail and abort
  mail -s "[wildebeest] update-symlinks warning: pid $pid still active" sysadmin@gnu.org < /dev/null > /dev/null
  exit -1
    else
  # Stale file, overwrite it, onwards and upwards
  echo $$ > /var/tmp/update-symlinks.pid
    fi
else
    # Output our PID to the pid file
    echo $$ > /var/tmp/update-symlinks.pid
fi

exec >> /var/log/wwwcvs/update-symlinks.log 2>&1

echo "Regenerating symlinks..."

WARNING="# GENERATED BY /home/wwwcvs/update-symlinks.sh DO NOT EDIT"
TMPFILE=`/bin/mktemp /tmp/hourly-website-update.XXXXXX || exit -1`
/usr/bin/find /var/www -type f -name '.symlinks' >> $TMPFILE

/home/wwwcvs/update-gnu-rewritemaps /var/www /home/wwwcvs/symlinks > /dev/null

printf "${WARNING}\n\n" > /home/wwwcvs/symlinks-nongnu-vhost.conf
cat $TMPFILE | xargs /home/wwwcvs/update-symlinks-xargs.py nongnu-vhost >> /home/wwwcvs/symlinks-nongnu-vhost.conf

printf "${WARNING}\n\n" > /home/wwwcvs/symlinks-nongnu.conf
cat $TMPFILE | xargs /home/wwwcvs/update-symlinks-xargs.py nongnu >> /home/wwwcvs/symlinks-nongnu.conf

CHANGED=0

dir1=/etc/apache2/symlinks
dir2=/home/wwwcvs/symlinks

# these need the -I to ignore comments.
for file in dir-map.txt html-map.txt nonhtml-map.txt; do
  diff -I "^#" -q {$dir1,$dir2}/$file
  if [[ "$?" != "0" ]]; then
    cp -f {$dir2,$dir1}/$file
    CHANGED=1
  fi
done

# nongnu files lack the comments and are in the top-level dir.
dir2=/home/wwwcvs
for file in symlinks-nongnu.conf symlinks-nongnu-vhost.conf; do
  diff -q {$dir1,$dir2}/$file
  if [[ "$?" != "0" ]]; then
    cp -f {$dir2,$dir1}/$file
    CHANGED=1
  fi
done

rm -f $TMPFILE
echo "Regeneration complete."

if [ "$CHANGED" == "1" ]; then
  echo "Restarting apache...."
  sudo /usr/sbin/apache2ctl graceful && echo "Restart successful."
else
  echo "No changes, no apache restart necessary"
fi

# Remove our lock/pid file

rm -f /var/tmp/update-symlinks.pid && echo "update-symlinks finished `date`" && exit 0