1 | #!/bin/sh |
---|
2 | # This script performs nfs updates on servers. |
---|
3 | # |
---|
4 | # $Header: /afs/.athena.mit.edu/astaff/project/moiradev/repository/moira/gen/nfs.sh,v 1.25 2000-05-25 05:43:22 zacheiss Exp $ |
---|
5 | |
---|
6 | # redirect output, and find the credentials directory (not robust, but |
---|
7 | # works for now). |
---|
8 | if [ -d /var/athena ] && [ -w /var/athena ]; then |
---|
9 | exec >/var/athena/moira_update.log 2>&1 |
---|
10 | else |
---|
11 | exec >/tmp/moira_update.log 2>&1 |
---|
12 | fi |
---|
13 | |
---|
14 | creddir=/var/athena |
---|
15 | if [ -d /usr/etc ]; then |
---|
16 | creddir=/usr/etc |
---|
17 | fi |
---|
18 | |
---|
19 | # The following exit codes are defined and MUST BE CONSISTENT with the |
---|
20 | # error codes the library uses: |
---|
21 | MR_NOCRED=47836470 |
---|
22 | MR_MISSINGFILE=47836473 |
---|
23 | MR_MKCRED=47836474 |
---|
24 | MR_TARERR=47836476 |
---|
25 | |
---|
26 | PATH=/etc:/bin:/usr/bin:/usr/etc:/usr/athena/etc |
---|
27 | |
---|
28 | TARFILE=/var/tmp/nfs.out |
---|
29 | SRCDIR=/var/tmp/nfs.dir |
---|
30 | |
---|
31 | uchost=`hostname | tr '[a-z]' '[A-Z]'` |
---|
32 | echo $uchost | egrep -e "\." >/dev/null |
---|
33 | if [ $? != 0 ]; then |
---|
34 | uchost=$uchost.MIT.EDU |
---|
35 | fi |
---|
36 | |
---|
37 | # Alert if the tar file does not exist |
---|
38 | test -r $TARFILE || exit $MR_MISSINGFILE |
---|
39 | |
---|
40 | # Make a temporary directory to unpack the tar file into |
---|
41 | rm -rf $SRCDIR |
---|
42 | mkdir $SRCDIR || exit $MR_MKCRED |
---|
43 | cd $SRCDIR || exit $MR_MKCRED |
---|
44 | |
---|
45 | # Extract everything |
---|
46 | tar xpf $TARFILE || exit $MR_TARERR |
---|
47 | |
---|
48 | for type in dirs quotas; do |
---|
49 | echo "Installing ${type}:" |
---|
50 | for i in $uchost.$type; do |
---|
51 | if [ -f $i ]; then |
---|
52 | # Convert from the filename HOST.@dev@device.type to /dev/device |
---|
53 | dev=`echo $i | sed "s,.${type},," | sed "s,${uchost}.,," | \ |
---|
54 | sed "s,@,/,g"` |
---|
55 | echo ${uchost}:$dev |
---|
56 | ./install_${type} $dev < $i |
---|
57 | if [ $? != 0 ]; then |
---|
58 | exit $MR_NOCRED |
---|
59 | fi |
---|
60 | if [ ${type} = "quotas" ]; then |
---|
61 | ./zero_quotas $dev < $i |
---|
62 | if [ $? != 0 ]; then |
---|
63 | exit $MR_NOCRED |
---|
64 | fi |
---|
65 | fi |
---|
66 | mv -f $i /var/tmp |
---|
67 | fi |
---|
68 | done |
---|
69 | done |
---|
70 | |
---|
71 | # build new credentials files |
---|
72 | rm -f $creddir/credentials.new |
---|
73 | cp ${uchost}.cred $creddir/credentials.new |
---|
74 | if [ $? != 0 ]; then |
---|
75 | exit $MR_NOCRED |
---|
76 | fi |
---|
77 | if [ -s $creddir/credentials.local ]; then |
---|
78 | cat $creddir/credentials.local >> $creddir/credentials.new |
---|
79 | fi |
---|
80 | |
---|
81 | # After this point, if /tmp gets cleared out by reactivate (which happens |
---|
82 | # on a combined server/workstation), we don't care. |
---|
83 | mkcred $creddir/credentials.new |
---|
84 | if [ $? != 0 ]; then |
---|
85 | exit $MR_MKCRED |
---|
86 | fi |
---|
87 | |
---|
88 | # Try to install the files |
---|
89 | for e in "" .dir .pag; do |
---|
90 | mv -f $creddir/credentials.new$e $creddir/credentials$e |
---|
91 | done |
---|
92 | |
---|
93 | # If any of them didn't get installed, fail |
---|
94 | for e in "" .dir .pag; do |
---|
95 | if [ ! -f $creddir/credentials$e ]; then |
---|
96 | exit $MR_NOCRED |
---|
97 | fi |
---|
98 | done |
---|
99 | |
---|
100 | # cleanup |
---|
101 | cd / |
---|
102 | rm -rf $SRCDIR |
---|
103 | test -f $TARFILE && rm -f $TARFILE |
---|
104 | test -f $0 && rm -f $0 |
---|
105 | |
---|
106 | exit 0 |
---|