Blame SOURCES/bz1391495-nfsserver-keep-options.patch

137983
diff -uNr a/heartbeat/nfsserver b/heartbeat/nfsserver
137983
--- a/heartbeat/nfsserver	2016-10-28 10:51:35.357385160 +0200
137983
+++ b/heartbeat/nfsserver	2016-10-28 13:22:16.844380108 +0200
137983
@@ -434,7 +434,12 @@
137983
 	# only write to the tmp /etc/sysconfig/nfs if sysconfig exists.
137983
 	# otherwise this distro does not support setting these options.
137983
 	if [ -d "/etc/sysconfig" ]; then
137983
-		echo "${key}=\"${value}\"" >> $file
137983
+		# replace if the value exists, append otherwise
137983
+		if grep "^\s*${key}=" $file ; then
137983
+			sed -i "s/\s*${key}=.*$/${key}=\"${value}\"/" $file
137983
+		else
137983
+			echo "${key}=\"${value}\"" >> $file
137983
+		fi
137983
 	elif [ "$requires_sysconfig" = "true" ]; then
137983
 		ocf_log warn "/etc/sysconfig/nfs not found, unable to set port and nfsd args."
137983
 	fi
137983
@@ -447,6 +452,11 @@
137983
 	local tmpconfig=$(mktemp ${HA_RSCTMP}/nfsserver-tmp-XXXXX)
137983
 	local statd_args
137983
 
137983
+	if [ -f "$NFS_SYSCONFIG" ]; then
137983
+		## Take the $NFS_SYSCONFIG file as our skeleton
137983
+		cp $NFS_SYSCONFIG $tmpconfig
137983
+	fi
137983
+
137983
 	# nfsd args
137983
 	set_arg "RPCNFSDARGS" "$OCF_RESKEY_nfsd_args" "$tmpconfig" "true"
137983
 
137983
@@ -477,14 +487,20 @@
137983
 
137983
 	# override local nfs config. preserve previous local config though.
137983
 	if [ -s $tmpconfig ]; then
137983
-		cat $NFS_SYSCONFIG | grep -e "$NFS_SYSCONFIG_AUTOGEN_TAG"
137983
+		cat $NFS_SYSCONFIG | grep -q -e "$NFS_SYSCONFIG_AUTOGEN_TAG" > /dev/null 2>&1
137983
 		if [ $? -ne 0 ]; then
137983
 			# backup local nfs config if it doesn't have our HA autogen tag in it.
137983
 			mv -f $NFS_SYSCONFIG $NFS_SYSCONFIG_LOCAL_BACKUP
137983
 		fi
137983
-		echo "# $NFS_SYSCONFIG_AUTOGEN_TAG" > $NFS_SYSCONFIG
137983
-		echo "# local config backup stored here, '$NFS_SYSCONFIG_LOCAL_BACKUP'" >> $NFS_SYSCONFIG
137983
-		cat $tmpconfig >> $NFS_SYSCONFIG
137983
+
137983
+		cat $tmpconfig | grep -q -e "$NFS_SYSCONFIG_AUTOGEN_TAG" > /dev/null 2>&1 
137983
+		if [ $? -ne 0 ]; then
137983
+			echo "# $NFS_SYSCONFIG_AUTOGEN_TAG" > $NFS_SYSCONFIG
137983
+			echo "# local config backup stored here, '$NFS_SYSCONFIG_LOCAL_BACKUP'" >> $NFS_SYSCONFIG
137983
+			cat $tmpconfig >> $NFS_SYSCONFIG
137983
+		else
137983
+			cat $tmpconfig > $NFS_SYSCONFIG
137983
+		fi
137983
 	fi
137983
 	rm -f $tmpconfig
137983
 }