#!/bin/ksh

#
# Copyright (c) 1996 by Sun Microsystems, Inc. All Rights Reserved.
#
# @(#)mntfs 1.5 98/09/04
#

#
# Usage: mntfs mntpoint remotehost remotedir mntoptions file-in-dir
#
# Mount the specified directory from remote host
# as a newsdirectory. Example:
#	mntfs /var/news/state newshost /var/news/state "ro" active
#
TEXTDOMAIN=isp_sns # We need to set this because if we give the domainname as an argument the xgettextsh
                   # fails.
export TEXTDOMAIN
script_name=$(basename $0)

usage()
{
    printf "`/usr/bin/gettext 'Usage: %s mntpoint remotehost remotedir mntoptions file-in-dir'`\n" $script_name
    exit 10
}

test $# -eq 5 || usage

if test -z "$_NEWS_INSTALL_TEST" ; then
    mount_cmd="mount"
    mkdir_cmd="mkdir -p"
    ln_cmd="ln"
else
    mount_cmd="echo mount"
    mkdir_cmd="echo mkdir -p"
    ln_cmd="echo ln"
fi

##  =()<. @<_PATH_NEWSLIB>@/innshellvars>()=
. /etc/opt/SUNWsns/innshellvars
##  =()<. @<_PATH_NEWSBIN>@/setup/mkaccess.shf>()=
. /opt/SUNWsns/bin/setup/mkaccess.shf

target=$1
origin=$2:$3
mntopts=$4
tstfile=$5

# Create target 
$mkdir_cmd $target
set_access $target

optflags=
if [ -n "$mntopts" ]; then
  optflags="-o $mntopts"
fi

# Mount directory and verify that the test file is readable in it.
mount $optflags $origin $target
mntStatus=$?
#echo "mntStatus is:  " $mntStatus

if [ $mntStatus -ne 0 ] ; then
  if [ -n "$tstfile" ]; then
   if [ ! -r $target/$tstfile ]; then
     printf "`/usr/bin/gettext '%s: %s does not contain %s; unmounting.'`\n" $script_name $origin $tstfile
     umount $target
     exit 1
   fi
 fi
# echo "failed mount"
 exit $mntStatus
fi
