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