#!/usr/bin/env bash
# 文件名: nfs_mount.sh
# 作  者: Shuhui@vqiu.cn
# 描  述: NFS客户端挂载脚本

export nfs_ser_pre="192.168.200"
export nfs_ser_host=$1
export nfs_ser_ip="${nfs_ser_pre}.${nfs_ser_host}"
export nfs_version=4.1
export nfs_cli_dir=/nfs_cli/node${nfs_ser_host}
export nfs_mount_opt="vers=${nfs_version},_netdev,rw,hard,intr,proto=tcp,rsize=1048576,wsize=1048576,timeo=600,retrans=2,noatime,nodiratime,nolock,noacl,sec=sys,noresvport,nconnect=8,nordirplus"


if [ -n "$nfs_ser_host" ]
then
	ping -c 2 $nfs_ser_ip >/dev/null 2>&1
	if [[ $? -eq "0" ]]
	then
		</dev/tcp/$nfs_ser_ip/2049 >/dev/null 2>&1
		if [[ $? -eq "0" ]]
		then
			mount | grep $nfs_cli_dir >/dev/null 2>&1
			if [[ $? -ne "0" ]]
			then
				mkdir -p $nfs_cli_dir
				mount -t nfs -o $nfs_mount_opt $nfs_ser_ip:/ $nfs_cli_dir
			else
				echo "Warning: [ $nfs_cli_dir ] already mounted." && exit 1
			fi
		else
			echo "Error: [ $nfs_ser_ip ] NFS service not running." && exit 1
		fi
	else
		echo "Error: [ $nfs_ser_ip ] host not alived." && exit 1
	fi
else
	echo "Usage: $(basename $0 .sh) host(1-255)"
	exit 1
fi
