]> andersk Git - moira.git/blob - gen/nfs.sh
1a4baaa14689908ae716b661d0bcc486d73c5bfb
[moira.git] / gen / nfs.sh
1 #!/bin/csh -f
2 # This script performs nfs updates on servers.
3 #
4 # $Header$
5
6 # The following exit codes are defined and MUST BE CONSISTENT with the
7 # MR error codes the library uses:
8 set MR_NOCRED = 47836470
9 set MR_MKCRED = 47836474
10 set MR_TARERR = 47836476
11
12 set path=(/etc /bin /usr/bin /usr/etc /usr/athena/etc)
13 set nonomatch
14
15 # The file containg the information for the update
16 set TARFILE=/var/tmp/nfs.out
17 # The directory into which we will empty the tarfile
18 set SRC_DIR=/var/tmp/nfs.dir
19
20 # Alert if the tarfile does not exist
21 if (! -r $TARFILE) then
22    exit $MR_TARERR
23 endif
24
25 # Create a fresh source directory
26 rm -rf $SRC_DIR
27 mkdir $SRC_DIR
28 chmod 755 $SRC_DIR
29
30 # Note that since MR is going to be exported, assuming .MIT.EDU is
31 # incorrect.  For now however, it is probably not worth the effort
32 # to canonicalize the hostname, especially with the upcoming update
33 # protocol redesign
34 set uchost=`hostname | tr '[a-z]' '[A-Z]'`.MIT.EDU
35
36 cd $SRC_DIR
37
38 # Just extract everything since some of what we need exists as
39 # hardlinks and tar doesn't deal well with extracting them in isolation.
40 tar xf $TARFILE
41 if ($status) exit $MR_TARERR
42
43 foreach type (dirs quotas)
44    echo "Installing ${type}:"
45    foreach i ( ${uchost}*.${type} )
46      if (-e $i) then
47         # Convert the from the filename HOST.@dev@device.type to /dev/device
48         set dev=`echo $i |  sed "s,.${type},," | sed "s,${uchost}.,," | sed "s,@,/,g"`
49         echo ${uchost}:$dev
50         ./install_${type} $dev < $i
51         if ($status) exit $status
52         if ($type == quotas) ./zero_quotas $dev < $i
53         if ($status) exit $status
54         # save the files used here for later debugging
55         mv $i /var/tmp
56      endif
57    end
58 end
59
60 # build new credentials files.
61 rm -f /usr/etc/credentials.new
62 cp ${uchost}.cred /usr/etc/credentials.new
63 if ($status) exit $MR_NOCRED
64 if (-e /usr/etc/credentials.local) then
65     cat /usr/etc/credentials.local >> /usr/etc/credentials.new
66 endif
67
68 # After this point, if /tmp gets cleared out by reactivate (which
69 # happens on a combined server/workstation) we don't care.
70
71 mkcred /usr/etc/credentials.new
72 if ($status) exit $MR_MKCRED
73
74 # Try to install the files
75 foreach e ( "" .dir .pag)
76    mv -f /usr/etc/credentials.new$e /usr/etc/credentials$e
77 end
78
79 # If any of them didn't get installed, fail
80 foreach e ( "" .dir .pag)
81    if (! -e /usr/etc/credentials$e) exit $MR_NOCRED
82 end
83
84
85
86 # cleanup
87 if ( -f $TARFILE ) rm -f $TARFILE
88 if ( -d $SRC_DIR ) then
89   cd $SRC_DIR/..
90   rm -rf $SRC_DIR
91 endif
92 if ( -f $0 ) rm -r $0
93
94 exit 0
This page took 0.138583 seconds and 3 git commands to generate.