#!/bin/ksh93
#  ALTRAN_PROLOG_BEGIN_TAG                                                    
#  This is an automatically generated prolog.                                  
#                                                                              
#  Copyright (C) Altran ACT S.A.S. 2020,2021.  All rights reserved.  
#                                                                              
#  ALTRAN_PROLOG_END_TAG                                                      
#                                                                              
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r721 src/43haes/usr/sbin/cluster/events/utils/cl_nfs_utils.sh 1.2 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1990,2016 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)  7d4c34b 43haes/usr/sbin/cluster/events/utils/cl_nfs_utils.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM
###############################################################################
# Name: getline_exports
# Description:
#       getline_exports gets the file system details from the exports file
#       /usr/es/sbin/cluster/etc/exports
# Arguments:
#                FileSystem  - filesystem to search
# Returns:
#                0 - success
#                1 - failure
# Environment:
#        NONE
#
###############################################################################

function getline_exports {

        PS4_FUNC="getline_exports"
        [[ $VERBOSE_LOGGING == high ]] && set -x

        cl_exports_data=""
        typeset line=""
        typeset -i flag=0
        fs=$1
        # validating the file system
        if [[ -z $fs ]]
        then
           return 1
        fi

        if [[ -r $EXPFILE ]]
        then
           cat $EXPFILE | while read -r line
           do

            line=${line#+([[:space:]])}
            line=${line%+([[:space:]])}

            # Only look at the part of the line preceding comments.
            if [[ "$line" == "#"* ]]
            then
               continue
            fi

            echo "$line" | grep -q "^[[:space:]]*${fs}[[:space:]]"
            if (( $? == 0 ))
            then
               flag=1
            fi

            if [[ $flag == 1 ]]
            then
               if [[ -n $(echo "$line" | grep -w '\\') ]]
               then
                  line=${line/%\\/} # Removing backslash character from the line
                  cl_exports_data="$cl_exports_data $line"
               else
                  cl_exports_data="$cl_exports_data $line"
                  break
               fi
            fi
           done

        fi

        return 0

}
###############################################################################
#
#   MAIN Main main
#
###############################################################################

PROGNAME=${0##*/}
if [[ "$VERBOSE_LOGGING" == "high" ]]
then
    set -x
    version='%I'
fi

typeset cl_exports_data=""
EXPFILE="/usr/es/sbin/cluster/etc/exports"
