]> andersk Git - moira.git/blob - gen/nfs.sh
removed trim & strsave, added fix_file & dequote
[moira.git] / gen / nfs.sh
1 #!/bin/csh -f
2 # This script performs nfs updates on 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_NOCRED 47836470
7 set SMS_MKCRED 47836474
8 set SMS_TARERR 47836476
9
10 set path=(/etc /bin /usr/bin /usr/etc)
11
12 # The file containg the information for the update
13 set TARFILE=/tmp/nfs.out
14 # The directory into which we will empty the tarfile
15 set SRC_DIR=/tmp/nfs.dir
16
17 # Create a frash source directory
18 rm -f $SRC_DIR
19 mkdir $SRC_DIR
20 chmod 755 $SRC_DIR
21
22 # Alert if the tarfile does not exist
23 if (! -r $TARFILE) then
24    exit SMS_TARERR
25 endif
26
27 # Note that since SMS is going to be exported, assuming .MIT.EDU is 
28 # incorrect.  For now however, it is probably not worth the effort
29 # to canonicalize the hostname, especially with the upcoming update
30 # protocol redesign
31 set uchost=`/bin/hostname | tr a-z A-Z`.MIT.EDU
32
33 cd $SRC_DIR
34
35 # Only files starting with $uchost, install_, and list- are needed.
36 # The files starting with list- are needed because the credentials
37 # files are hard links to them.  Tar will fail if they are not extracted.
38 foreach file (`/bin/tar tf $TARFILE | awk '{print $1}'`)
39    if (($file =~ ./${uchost}*) || \
40        ($file =~ ./install_*) || \
41        ($file =~ ./list-*)) then
42       tar xf $TARFILE $file
43       if ($status) exit SMS_TARERR
44    endif
45 end
46
47 foreach type (dirs quotas)
48    echo "Installing ${type}:"
49    foreach i ( ${uchost}*.${type} )
50       # Convert the from the filename HOST.@dev@device.type to /dev/device
51       set dev=`echo $i |  sed 's;.${type};;' | sed 's;${uchost}.;;' | \
52           sed 's;@;/;g'`
53       echo ${uchost}:$dev
54       ./install_${type} $dev < $i
55       if ($status) exit $status
56    end
57 end
58
59 # build new credentials files.
60 rm -f /usr/etc/credentials.new
61 cp ${uchost}.cred /usr/etc/credentials.new
62 if ($status) exit SMS_SMS_NOCRED
63
64 /usr/etc/mkcred /usr/etc/credentials.new
65 if ($status) exit SMS_MKCRED
66
67 # Try to install the files
68 foreach e ( "" .dir .pag)
69    mv -f /usr/etc/credentials.new$e /usr/etc/credentials$e
70 end
71
72 # If any of them didn't get installed, fail
73 foreach e ( "" .dir .pag)
74    if (! -e /usr/etc/credentials$e) exit SMS_NOCRED
75 end
76
77 # cleanup
78 rm -f $TARFILE
79 cd $SRC_DIR/..
80 rm -rf $SRC_DIR
81 rm $0
82
83 exit 0
84
85 #
86 #       $Source$
87 #       $Header$
88 #
This page took 0.042021 seconds and 5 git commands to generate.