]> andersk Git - moira.git/blob - gen/hesiod.sh
fixed a syntax error
[moira.git] / gen / hesiod.sh
1 #!/bin/csh -f
2 # This script performs updates of hesiod files on hesiod servers.  
3
4 # The following exit codes are defined and MUST BE CONSISTENT with the
5 # SMS error codes the library uses:
6 set SMS_HESFILE =       47836472
7 set SMS_MISSINGFILE =   47836473
8 set SMS_NAMED =         47836475
9 set SMS_TARERR =        47836476
10
11 # File that will contain the necessary information to be updated
12 set TARFILE=/tmp/hesiod.out
13 # Directory into which we will empty the tarfile
14 set SRC_DIR=/etc/athena/_nameserver
15 # Directory into which we will put the final product
16 set DEST_DIR=/etc/athena/nameserver
17
18 # Create the destination directory if it doesn't exist
19 if (! -d $DEST_DIR) then
20    /bin/rm -f $DEST_DIR
21    /bin/mkdir $DEST_DIR
22    /bin/chmod 755 $DEST_DIR
23 endif
24
25 # There is reason for $SRC_DIR and $DEST_DIR to be on the same disk
26 # parition, so find out where $DEST_DIR is and put $SRC_DIR there too.
27 set old = $cwd
28 chdir $DEST_DIR
29 # Don't use $cwd; it won't follow the link
30 set CUR_DIR = `pwd`
31 set SRC_DIR_TMP = $CUR_DIR:h/_nameserver
32 if (! -d $SRC_DIR_TMP) then
33    /bin/rm -f $SRC_DIR_TMP
34    /bin/mkdir $SRC_DIR_TMP
35    /bin/chmod 755 $SRC_DIR_TMP
36 endif
37 if ($SRC_DIR_TMP != $SRC_DIR) ln -s $SRC_DIR_TMP $SRC_DIR
38 cd $old
39 unset old SRC_DIR_TMP
40
41 # Alert if tarfile doesn't exist
42 if (! -r $TARFILE) exit $SMS_MISSINGFILE
43
44 # Empty the tar file one file at a time and move each file to the
45 # appropriate place only if it is not zero length. 
46 cd $SRC_DIR
47 foreach  file (`/bin/tar tf $TARFILE | awk '{print $1}' | sed 's;/$;;'`)
48    if (. == $file) continue
49
50    rm -rf $file
51    echo extracting $file
52    /bin/tar xf $TARFILE $file
53    # Don't put up with errors extracting the information
54    if ($status) exit $SMS_TARERR
55    # Make sure the file is not zero-length
56    if (! -z $file) then
57       /bin/mv -f $file $DEST_DIR
58       if ($status != 0) exit $SMS_HESFILE
59    else
60       /bin/rm -f $file
61       exit $SMS_MISSINGFILE
62    endif
63 end
64
65 # Kill off the current named and remove the named.pid file.  It is
66 # important that this file be removed since the script uses its
67 # existance as evidence that named as has been successfully restarted.
68
69 # Use /bin/kill because, due to a bug in some versions of csh, failure
70 # of a builtin will cause the script to abort
71 /bin/kill -KILL `/bin/cat /etc/named.pid`
72 rm -f /etc/named.pid
73
74 # Restart named.
75 (unlimit; /etc/named)
76
77 # Before trying to reimpliment this timeout mechanism using interrupts, 
78 # be sure to check and make sure that it will work on both types of 
79 # machines.  As of 6.0B, RT csh didn't respond correctly to onintr.
80 #
81 # This timeout is implemented by having the shell check TIMEOUT times
82 # for the existance of /etc/named.pid and to sleep INTERVAL seconds
83 # between each check.
84
85 set TIMEOUT=60                  # number of INTERVALS until timeout
86 set INTERVAL=60                 # number of seconds between checks
87 set i = 0
88 while ($i < $TIMEOUT)
89    sleep $INTERVAL
90    if (-f /etc/named.pid) break
91    @ i++
92 end
93
94 # Did it time out?
95 if ($i == $TIMEOUT) exit $SMS_NAMED
96
97 # Clean up!
98 /bin/rm -f $TARFILE
99 /bin/rm -f $0
100
101 exit 0
102
103 #
104 #       $Source$
105 #       $Header$
106 #
This page took 0.043812 seconds and 5 git commands to generate.