]> andersk Git - moira.git/blame - gen/nfs.sh
correct an exit status to cause a more useful error message
[moira.git] / gen / nfs.sh
CommitLineData
f4f32185 1#!/bin/sh
39f6c9df 2# This script performs nfs updates on servers.
e46282d6 3#
568331c6 4# $Header$
39f6c9df 5
f4f32185 6# redirect output, and find the credentials directory (not robust, but
7# works for now).
8if [ -d /var/athena ] && [ -w /var/athena ]; then
9 creddir=/var/athena
10 exec >/var/athena/moira_update.log 2>&1
11else
12 creddir=/usr/etc
13 exec >/tmp/moira_update.log 2>&1
14fi
15
16# The following exit codes are defined and MUST BE CONSISTENT with the
59ec8dae 17# error codes the library uses:
f4f32185 18MR_NOCRED=47836470
19MR_MISSINGFILE=47836473
20MR_MKCRED=47836474
21MR_TARERR=47836476
22
23PATH=/etc:/bin:/usr/bin:/usr/etc:/usr/athena/etc
24
25TARFILE=/var/tmp/nfs.out
26SRCDIR=/var/tmp/nfs.dir
27
28uchost=`hostname | tr '[a-z]' '[A-Z]'`
29echo $uchost | egrep -e "\." >/dev/null
30if [ $? != 0 ]; then
31 uchost=$uchost.MIT.EDU
32fi
33
34# Alert if the tar file does not exist
35test -r $TARFILE || exit $MR_MISSINGFILE
36
37# Make a temporary directory to unpack the tar file into
38rm -rf $SRCDIR
39mkdir $SRCDIR || exit $MR_MKCRED
40cd $SRCDIR || exit $MR_MKCRED
41
42# Extract everything
43tar xpf $TARFILE || exit $MR_TARERR
44
45for type in dirs quotas; do
46 echo "Installing ${type}:"
47 for i in $uchost.$type; do
48 if [ -f $i ]; then
49 # Convert from the filename HOST.@dev@device.type to /dev/device
50 dev=`echo $i | sed "s,.${type},," | sed "s,${uchost}.,," | \
51 sed "s,@,/,g"`
52 echo ${uchost}:$dev
53 ./install_${type} $dev < $i
54 if [ $? != 0 ]; then
55 exit $MR_NOCRED
56 fi
57 if [ ${type} = "quotas" ]; then
58 ./zero_quotas $dev < $i
59 if [ $? != 0 ]; then
60 exit $MR_NOCRED
61 fi
62 fi
63 mv -f $i /var/tmp
64 fi
65 done
66done
67
68# build new credentials files
fec3cea4 69rm -f $creddir/credentials.new
70cp ${uchost}.cred $creddir/credentials.new
f4f32185 71if [ $? != 0 ]; then
72 exit $MR_NOCRED
73fi
74if [ -s $creddir/credentials.local ]; then
fec3cea4 75 cat $creddir/credentials.local >> $creddir/credentials.new
f4f32185 76fi
51bf07bb 77
f4f32185 78# After this point, if /tmp gets cleared out by reactivate (which happens
79# on a combined server/workstation), we don't care.
fec3cea4 80mkcred $creddir/credentials.new
f4f32185 81if [ $? != 0 ]; then
82 exit $MR_MKCRED
83fi
39f6c9df 84
85# Try to install the files
f4f32185 86for e in "" .dir .pag; do
87 mv -f $creddir/credentials.new$e $creddir/credentials$e
88done
51bf07bb 89
39f6c9df 90# If any of them didn't get installed, fail
f4f32185 91for e in "" .dir .pag; do
92 if [ ! -f $creddir/credentials$e ]; then
93 exit $MR_NOCRED
94 fi
95done
e46282d6 96
39f6c9df 97# cleanup
f4f32185 98cd /
99rm -rf $SRCDIR
100test -f $TARFILE && rm -f $TARFILE
101test -f $0 && rm -f $0
39f6c9df 102
103exit 0
This page took 0.096136 seconds and 5 git commands to generate.