]> andersk Git - moira.git/blobdiff - gen/nfs.sh
Diane Delgado's changes for a fixed table-locking order
[moira.git] / gen / nfs.sh
index 02a79474c02c8df4ba7937eec78432df93218793..21c1899353f27940752833a6a91f29e0a0b39868 100644 (file)
@@ -1,39 +1,91 @@
 #!/bin/csh -f
-set path=(/bin /usr/bin /etc /usr/etc )
-set TARFILE=/tmp/nfs
-set TMPDIR=/tmp/nfs.dir
-
-if ( ! -d $TMPDIR ) then
-       rm -f $TMPDIR
-       mkdir $TMPDIR
-       chmod 755 $TMPDIR
+# This script performs nfs updates on servers.
+#
+# $Header$
+
+# The following exit codes are defined and MUST BE CONSISTENT with the
+# MR error codes the library uses:
+set MR_NOCRED = 47836470
+set MR_MKCRED = 47836474
+set MR_TARERR = 47836476
+
+set path=(/etc /bin /usr/bin /usr/etc /usr/athena/etc)
+set nonomatch
+
+# The file containg the information for the update
+set TARFILE=/tmp/nfs.out
+# The directory into which we will empty the tarfile
+set SRC_DIR=/tmp/nfs.dir
+
+# Alert if the tarfile does not exist
+if (! -r $TARFILE) then
+   exit $MR_TARERR
 endif
 
-cd $TMPDIR
-tar xf $TARFILE
-if ($status) exit 1
+# Create a fresh source directory
+rm -rf $SRC_DIR
+mkdir $SRC_DIR
+chmod 755 $SRC_DIR
 
-set uchost=`hostname|tr a-z A-Z`.MIT.EDU
-set uchostrev=`echo $uchost | rev`
+# Note that since MR is going to be exported, assuming .MIT.EDU is 
+# incorrect.  For now however, it is probably not worth the effort
+# to canonicalize the hostname, especially with the upcoming update
+# protocol redesign
+set uchost=`hostname | tr '[a-z]' '[A-Z]'`.MIT.EDU
 
-foreach i ( ${uchost}* )
-       set t1=`echo $i | rev`
-       set dev=`basename $t1 :$uchostrev | rev | sed 's;@;/;g'`
+cd $SRC_DIR
 
-       echo ${uchost}:$dev
+# Just extract everything since some of what we need exists as
+# hardlinks and tar doesn't deal well with extracting them in isolation.
+tar xf $TARFILE
+if ($status) exit $MR_TARERR
 
-       ./install_fs $dev < $i
+foreach type (dirs quotas)
+   echo "Installing ${type}:"
+   foreach i ( ${uchost}*.${type} )
+     if (-e $i) then
+       # Convert the from the filename HOST.@dev@device.type to /dev/device
+       set dev=`echo $i |  sed "s,.${type},," | sed "s,${uchost}.,," | sed "s,@,/,g"`
+       echo ${uchost}:$dev
+       ./install_${type} $dev < $i
+       if ($status) exit $status
+       if ($type == quotas) ./zero_quotas $dev < $i
+       if ($status) exit $status
+       # save the files used here for later debugging
+       mv $i /tmp
+     endif
+   end
 end
 
-# build new credentials file.
+# build new credentials files.
 rm -f /usr/etc/credentials.new
-cp credentials /usr/etc/credentials.new
-if ($status) exit 1
+cp ${uchost}.cred /usr/etc/credentials.new
+if ($status) exit $MR_NOCRED
 
-/usr/etc/mkcred /usr/etc/credentials.new
-if ($status) exit 1
+# After this point, if /tmp gets cleared out by reactivate (which
+# happens on a combined server/workstation) we don't care.
 
+mkcred /usr/etc/credentials.new
+if ($status) exit $MR_MKCRED
+
+# Try to install the files
+foreach e ( "" .dir .pag)
+   mv -f /usr/etc/credentials.new$e /usr/etc/credentials$e
+end
+
+# If any of them didn't get installed, fail
 foreach e ( "" .dir .pag)
-       mv /usr/etc/credentials.new$e /usr/etc/credentials$e
+   if (! -e /usr/etc/credentials$e) exit $MR_NOCRED
 end
 
+
+
+# cleanup
+if ( -f $TARFILE ) rm -f $TARFILE
+if ( -d $SRC_DIR ) then
+  cd $SRC_DIR/..
+  rm -rf $SRC_DIR
+endif
+if ( -f $0 ) rm -r $0
+
+exit 0
This page took 0.039419 seconds and 4 git commands to generate.