#! /bin/sh

#pragma ident "@(#)nfs_fix_sharetab.sh   1.4     01/03/28 SMI"
#
#       Copyright (C) 1994 Sun Microsystems, Inc.
#


#
# Usage: nfs_fix_sharetab [-2]
#
# Groks the /etc/dfs/sharetab file and deletes lines that are
# illegal, in that they contain fewer than 4 fields.  An important
# special case of this is to delete empty lines.
#
# The switch -2 means that this is pass 2 of the recursive call from
# this script to itself.  The purpose of that is that the initial
# call merely grabs a file lock and then does a recursive call, with the
# -2 switch, to the script again, with the nested call doing the
# actual work.
# 

prog=`basename $0`
fullprog="$0"

switch=$1
fname="/etc/dfs/sharetab"
newfname="${fname}.${prog}.new"

if [ ! -s $fname ]; then
    # File is non-existent or empty: no work to do.
    exit 0
fi

nawk '{ if (NF < 4) exit 99 }' $fname >/dev/null
if [ $? -ne 99 ]; then
    # File is already okay.  No work to do.
    exit 0
fi

if [ -z "$switch" ]; then
    # Initial call.  Lock the file and call ourselves recursively:
    exec lockedrun $fname $fullprog -2
fi

awk '(NF < 4 )' $fname > /var/opt/SUNWcluster/run/awk.output
log_info "SUNWcluster.hanfs.3050" "File $fname contains some garbage lines, deleting them."
awk '(NF >= 4)' $fname > $newfname
cp $newfname $fname
rm -f /var/opt/SUNWcluster/run/awk.output $newfname
sync >/dev/null 2>&1 &
exit 0
