]>
Commit | Line | Data |
---|---|---|
39f6c9df | 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 | |
de9119eb | 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 | |
39f6c9df | 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 | |
de9119eb | 42 | if (! -r $TARFILE) exit $SMS_MISSINGFILE |
39f6c9df | 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. | |
de56407f | 46 | cd $SRC_DIR |
de9119eb | 47 | foreach file (`/bin/tar tf $TARFILE | awk '{print $1}' | sed 's;/$;;'`) |
48 | if (. == $file) continue | |
39f6c9df | 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 | |
de9119eb | 54 | if ($status) exit $SMS_TARERR |
39f6c9df | 55 | # Make sure the file is not zero-length |
56 | if (! -z $file) then | |
57 | /bin/mv -f $file $DEST_DIR | |
de9119eb | 58 | if ($status != 0) exit $SMS_HESFILE |
39f6c9df | 59 | else |
60 | /bin/rm -f $file | |
de9119eb | 61 | exit $SMS_MISSINGFILE |
39f6c9df | 62 | endif |
63 | end | |
de56407f | 64 | |
39f6c9df | 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? | |
de9119eb | 95 | if ($i == $TIMEOUT) exit $SMS_NAMED |
39f6c9df | 96 | |
97 | # Clean up! | |
98 | /bin/rm -f $TARFILE | |
99 | /bin/rm -f $0 | |
f89684dc | 100 | |
39f6c9df | 101 | exit 0 |
ceb34639 | 102 | |
de56407f | 103 | # |
104 | # $Source$ | |
105 | # $Header$ | |
106 | # |