#!/bin/sh
#
# by ymc-dabe
# Adds/removes an entry in /etc/exports
#

. /usr/lib/lib-fliwi/ymc-common.sh || exit 1

fliwiCommand=$3
USAGE="usage: $0 pathToExport exportOptions {start|stop|status}";
exportPath=$1
exportOptions=$2

fliwiScriptName=$(basename $0)

usage()
{
    echo $USAGE >&2
}

if [ $# != 3 ]; then
    usage
    exit 1
fi


nfsv3_status()
{
    if [ $(cat /etc/exports | grep -c -F "$exportPath $exportOptions") -gt 0 ]; then
      echo "running"
    else
      echo "stopped"
    fi
}

nfsv3_add()
{
  ### Add an entry in /etc/exports //start
  fliwi_modify_file_add_block_start /etc/exports "Added by $fliwiScriptName"
  echo "$exportPath $exportOptions" >> /etc/exports
  fliwi_modify_file_add_block_end /etc/exports "Added by $fliwiScriptName"
  ### Add an entry in /etc/exports //end
}

nfsv3_remove()
{
  ### Wash out possibly existing entries added by this script in /etc/exports
  fliwi_modify_file_remove_added_block /etc/exports "Added by $fliwiScriptName"
}



case $fliwiCommand in
  start)        nfsv3_add;;
  stop)         nfsv3_remove;;
  status)       nfsv3_status;;
  *)            usage
                exit 1
                ;;
esac

