#!/bin/sh
#######################################################################
# copyright (C) 2015 by NetApp.  All Rights Reserved.
#
#######################################################################
prog_name="netapp_nfs_netgroup_check"
#
# Output a message
# input: string
# output: string
#
report()
{
    echo "$1";
}

#######
# BEGIN
# check for NFS license and if its present, throw the below warning.
# Check for netgroups in export policy before giving out the warning.
#######

cap_check_cmd="set test;capability canbe-enabled -cap-in DATA_ONTAP.8.3.1;";
cap_cmd_output=`ngsh -c \"$cap_check_cmd\"`;

echo "$cap_cmd_output" | grep "DATA_ONTAP.8.3.1" > /dev/null;
cap_cmd_res=$?;

if [ $cap_cmd_res -eq 0 ]; then
    exit;
fi

cmd_input="set diag;license show;";
cmd_output=`ngsh -c \"$cmd_input\"`;
report "netapp_nfs_netgroup_check script begin";
echo "$cmd_output" | grep "NFS" > /dev/null;
cmd_res1=$?;
cmd_input="set diag;export-policy rule show -fields clientmatch;";
cmd_output=`ngsh -c \"$cmd_input\"`;
echo "$cmd_output" | grep "@" > /dev/null;
cmd_res2=$?;
if ([ $cmd_res1 -eq 0 ] && [ $cmd_res2 -eq 0 ]); then
     report # newline
     report # newline
     report "Warning: NFS and netgroups are in use. Search for TR-4379: Name Services Best Practice Guide on"
     report " www.netapp.com for information about PTR records before upgrading the cluster to this image."
     report # newline
     report # newline
fi
