]> andersk Git - moira.git/blobdiff - gen/nfs.sh
Make sure $last is initialized the first time we use it.
[moira.git] / gen / nfs.sh
index 02a79474c02c8df4ba7937eec78432df93218793..67514adbeaddf4dcf3272c22518cdfef9b4b8583 100644 (file)
-#!/bin/csh -f
-set path=(/bin /usr/bin /etc /usr/etc )
-set TARFILE=/tmp/nfs
-set TMPDIR=/tmp/nfs.dir
+#!/bin/sh
+# This script performs nfs updates on servers.
+#
+# $Header$
 
-if ( ! -d $TMPDIR ) then
-       rm -f $TMPDIR
-       mkdir $TMPDIR
-       chmod 755 $TMPDIR
-endif
+# redirect output, and find the credentials directory (not robust, but
+# works for now).
+if [ -d /var/athena ] && [ -w /var/athena ]; then
+    exec >/var/athena/moira_update.log 2>&1
+else 
+    exec >/tmp/moira_update.log 2>&1
+fi
 
-cd $TMPDIR
-tar xf $TARFILE
-if ($status) exit 1
+creddir=/var/athena
+if [ -d /usr/etc ]; then
+    creddir=/usr/etc
+fi
 
-set uchost=`hostname|tr a-z A-Z`.MIT.EDU
-set uchostrev=`echo $uchost | rev`
+# The following exit codes are defined and MUST BE CONSISTENT with the 
+# error codes the library uses:
+MR_NOCRED=47836470
+MR_MISSINGFILE=47836473
+MR_MKCRED=47836474
+MR_TARERR=47836476
 
-foreach i ( ${uchost}* )
-       set t1=`echo $i | rev`
-       set dev=`basename $t1 :$uchostrev | rev | sed 's;@;/;g'`
+PATH=/etc:/bin:/usr/bin:/usr/etc:/usr/athena/etc
 
-       echo ${uchost}:$dev
+TARFILE=/var/tmp/nfs.out
+SRCDIR=/var/tmp/nfs.dir
 
-       ./install_fs $dev < $i
-end
+uchost=`hostname | tr '[a-z]' '[A-Z]'`
+echo $uchost | egrep -e "\." >/dev/null
+if [ $? != 0 ]; then
+    uchost=$uchost.MIT.EDU
+fi
 
-# build new credentials file.
-rm -f /usr/etc/credentials.new
-cp credentials /usr/etc/credentials.new
-if ($status) exit 1
+# Alert if the tar file does not exist
+test -r $TARFILE || exit $MR_MISSINGFILE
 
-/usr/etc/mkcred /usr/etc/credentials.new
-if ($status) exit 1
+# Make a temporary directory to unpack the tar file into
+rm -rf $SRCDIR
+mkdir $SRCDIR || exit $MR_MKCRED
+cd $SRCDIR || exit $MR_MKCRED
 
-foreach e ( "" .dir .pag)
-       mv /usr/etc/credentials.new$e /usr/etc/credentials$e
-end
+# Extract everything
+tar xpf $TARFILE || exit $MR_TARERR
 
+for type in dirs quotas; do
+    echo "Installing ${type}:"
+    for i in $uchost.$type; do
+       if [ -f $i ]; then
+           # Convert from the filename HOST.@dev@device.type to /dev/device
+           dev=`echo $i | sed "s,.${type},," | sed "s,${uchost}.,," | \
+               sed "s,@,/,g"`
+           echo ${uchost}:$dev
+           ./install_${type} $dev < $i
+           if [ $? != 0 ]; then
+               exit $MR_NOCRED
+           fi
+           if [ ${type} = "quotas" ]; then
+               ./zero_quotas $dev < $i
+               if [ $? != 0 ]; then
+                   exit $MR_NOCRED
+               fi
+           fi
+           mv -f $i /var/tmp
+        fi
+    done
+done
+    
+# build new credentials files
+rm -f $creddir/credentials.new
+cp ${uchost}.cred $creddir/credentials.new
+if [ $? != 0 ]; then
+    exit $MR_NOCRED
+fi
+if [ -s $creddir/credentials.local ]; then
+    cat $creddir/credentials.local >> $creddir/credentials.new
+fi
+
+# After this point, if /tmp gets cleared out by reactivate (which happens
+# on a combined server/workstation), we don't care.
+mkcred $creddir/credentials.new
+if [ $? != 0 ]; then
+    exit $MR_MKCRED
+fi
+
+# Try to install the files
+for e in "" .dir .pag; do
+    mv -f $creddir/credentials.new$e $creddir/credentials$e
+done
+
+# If any of them didn't get installed, fail
+for e in "" .dir .pag; do
+    if [ ! -f $creddir/credentials$e ]; then
+       exit $MR_NOCRED
+    fi
+done
+
+# cleanup
+cd /
+rm -rf $SRCDIR
+test -f $TARFILE && rm -f $TARFILE
+test -f $0 && rm -f $0
+
+exit 0
This page took 0.085824 seconds and 4 git commands to generate.