source: trunk/third/moira/gen/access.sh @ 24319

Revision 24319, 1.9 KB checked in by broder, 14 years ago (diff)
New Moira snapshot from SVN.
  • Property svn:executable set to *
Line 
1#!/bin/sh
2#
3# $HeadURL: svn+ssh://svn.mit.edu/moira/trunk/moira/gen/access.sh $ $Id: access.sh 3956 2010-01-05 20:56:56Z zacheiss $
4
5PATH=/sbin:/bin:/usr/sbin:/usr/bin:/etc:/usr/etc:/usr/athena/bin:/usr/local/bin
6export PATH
7
8if [ -d /var/athena ] && [ -w /var/athena ]; then
9    exec >/var/athena/moira_update.log 2>&1
10else
11    exec >/tmp/moira_update.log 2>&1
12fi
13
14# The following exit codes are defined and MUST BE CONSISTENT with
15# error codes the library uses:
16MR_MKCRED=47836474
17MR_MISSINGFILE=47836473
18MR_NOCRED=47836470
19
20root=/usr/local/sendmail
21
22if [ -s $root/etc/access.new ]; then
23    cp /dev/null $root/etc/access.tmp
24   
25    if [ -s $root/etc/efl-access ]; then
26        cat $root/etc/efl-access >> $root/etc/access.tmp
27    fi
28
29    cat $root/etc/access.new >> $root/etc/access.tmp
30    mv $root/etc/access.tmp $root/etc/access.new
31    chmod 644 $root/etc/access.new
32else
33    exit $MR_MISSINGFILE
34fi
35
36if [ ! -s $root/etc/access ]; then
37    logger -p mail.error -t access.sh "No current access file, aborting."
38    exit $MR_NOCRED
39fi
40
41# Play it safe and be sure we have reasonable data
42olines=`wc -l $root/etc/access |  awk '{print $1}'`
43nlines=`wc -l $root/etc/access.new | awk '{print $1}'`
44diff=`expr $nlines - $olines`
45thresh=`expr $olines / 10`
46
47# Catch the zero case
48if [ $nlines -eq 0 ]; then
49    logger -p mail.error -t access.sh "Recieved empty access file, aborting."
50    exit $MR_MISSINGFILE
51fi
52
53# If its a greater than 10% shift bomb out to be safe
54if [ $diff -gt $thresh ]; then
55    logger -p mail.error -t access.sh "Access changes threshold exceeded, aborting."
56    exit $MR_NOCRED
57fi
58
59cp /dev/null $root/etc/access.new.db
60
61$root/sbin/makemap btree $root/etc/access.new < $root/etc/access.new
62if [ $? != 0 ]; then
63    exit $MR_MKCRED
64fi
65
66mv $root/etc/access $root/etc/access.old
67mv $root/etc/access.new $root/etc/access
68rm -f $root/etc/access.old.db
69ln $root/etc/access.db $root/etc/access.old.db
70mv $root/etc/access.new.db $root/etc/access.db
71
72rm -f $0
73exit 0
Note: See TracBrowser for help on using the repository browser.