+

Added installation script

Benjamin Renard [2011-01-17 17:00:42]
Added installation script
Filename
install.sh
diff --git a/install.sh b/install.sh
new file mode 100644
index 0000000..03da433
--- /dev/null
+++ b/install.sh
@@ -0,0 +1,74 @@
+#!/bin/bash
+
+SD=$( dirname $0 )
+SD=$( pwd $SD )
+SRC=$SD/check_mem
+DD=/usr/local/lib/nagios/plugins
+DST=$DD/check_mem
+
+NAGIOS_PLUGINS_CFG_DIR=/etc/nagios-plugins/config
+NAGIOS_PLUGINS_CFG_DST=$NAGIOS_PLUGINS_CFG_DIR/mem.cfg
+
+[ ! -d $DD ] && mkdir -p $DD
+
+DO=1
+if [ -e $DST ]
+then
+	ASK=1
+	if [ -L $DST ]
+	then
+		D=`ls -l $DST|awk '{print $11}'`
+		if [ "$D" = "$SRC" ]
+		then
+			echo "Symbolic link $DST already exist. Pass."
+			ASK=0
+			DO=0
+		fi
+	fi
+	if [ $ASK -eq 1 ]
+	then
+		echo "File $DST already exists."
+		echo -n "Abort (Y,n) ? "
+		read a
+		[ "$a" != "N" -a "$a" != "n" ] && exit
+		echo "Saved old file in $DST.orig"
+		mv $DST $DST.orig
+	fi
+fi
+
+[ $DO -eq 1 ] && ln -s $SRC $DST
+
+[ ! -d $NAGIOS_PLUGINS_CFG_DIR ] && mkdir -p $NAGIOS_PLUGINS_CFG_DIR
+
+DO=1
+TMP=`mktemp`
+echo "# 'check_mem' command definition
+define command {
+	command_name	check_mem
+	command_line	$DST -w \$ARG1\$,\$ARG2\$ -c \$ARG3\$,\$ARG4\$
+}" > $TMP
+
+if [ -e $NAGIOS_PLUGINS_CFG_DST ]
+then
+	ASK=1
+	if [ ! -n "`diff $NAGIOS_PLUGINS_CFG_DST $TMP`" ]
+	then
+		echo "Configuration file already and is correct. Pass."
+		ASK=0
+		DO=0
+	fi
+	if [ $ASK -eq 1 ]
+	then
+		echo "File $NAGIOS_PLUGINS_CFG_DST already exists."
+		echo -n "Abort (Y,n) ? "
+		read a
+		[ "$a" != "N" -a "$a" != "n" ] && exit
+		echo "Saved old configuration file in $NAGIOS_PLUGINS_CFG_DST.orig"
+		mv "$NAGIOS_PLUGINS_CFG_DST" "$NAGIOS_PLUGINS_CFG_DST.orig"
+	fi
+fi
+
+[ $DO -eq 1 ] && cp $TMP $NAGIOS_PLUGINS_CFG_DST
+rm -f $TMP
+
+
ViewGit