[Pkg-nagios-changes] [pkg-nagios] r1748 - nagios3/trunk/debian

Alexander Wirt formorer at alioth.debian.org
Sat Sep 5 13:59:36 UTC 2009


Author: formorer
Date: 2009-09-05 13:59:36 +0000 (Sat, 05 Sep 2009)
New Revision: 1748

Added:
   nagios3/trunk/debian/nagios3-cgi.postinst
   nagios3/trunk/debian/nagios3-cgi.postrm
   nagios3/trunk/debian/nagios3-cgi.prerm
Log:
Fix post* scripts for cgi move

Added: nagios3/trunk/debian/nagios3-cgi.postinst
===================================================================
--- nagios3/trunk/debian/nagios3-cgi.postinst	                        (rev 0)
+++ nagios3/trunk/debian/nagios3-cgi.postinst	2009-09-05 13:59:36 UTC (rev 1748)
@@ -0,0 +1,121 @@
+#!/bin/bash
+
+set -e
+
+# some shorthands for sanity
+en="/etc/nagios3"
+enc="/etc/nagios3/conf.d"
+usn="/usr/share/nagios3"
+
+. /usr/share/debconf/confmodule
+. $usn/debian/httpd.webapps-common
+
+if [ -n "$NAG3DEBUG" ]; then
+  echo "now debugging $0 $@"
+  set -x
+fi
+
+# location of the default apache configuration for nagios.
+apacheconf=$en/apache2.conf
+# location of the default htpasswd authentication file.
+htpw=$en/htpasswd.users
+
+setperm() {
+    local user="$1"
+    local group="$2"
+    local mode="$3"
+    local file="$4"
+    shift 4
+    # only do something when no setting exists
+    if ! dpkg-statoverride --list "$file" >/dev/null 2>&1; then
+      chown "$user":"$group" "$file"
+      chmod "$mode" "$file"
+    fi
+}
+
+case "$1" in
+  configure)
+    if ! getent passwd nagios > /dev/null ; then
+      echo 'Adding system-user for nagios' 1>&2
+      adduser --system --group --home /var/lib/nagios \
+              --disabled-login --force-badname nagios > /dev/null
+    fi
+
+	# get the list of selected servers
+	db_get nagios3/httpd
+	servers=$(echo $RET | sed -e 's/,/ /g')
+	db_get nagios3/adminpassword
+	admpass="$RET"
+	# get whether they want support for 1.x urls:
+	db_get nagios3/nagios1-in-apacheconf
+	nagiosone="$RET"
+
+	# register apache2.conf via ucf:
+	if [ "$nagiosone" = "true" ]; then
+		ucf --debconf-ok /usr/share/doc/nagios3-common/examples/apache2.nagios1.conf $apacheconf
+	else
+		ucf --debconf-ok /usr/share/doc/nagios3-common/examples/apache2.conf $apacheconf
+	fi
+
+	# and do some voodoo to detect default gw and make a host of it
+	tmpgw=$(mktemp)
+	set -- $(route -n 2>/dev/null| grep '^0.0.0.0' | head -n1)
+	DEFAULTGW=$2
+	if [ -z "$DEFAULTGW" ]; then
+	  echo "WARN: no default gateway found (/proc not mounted?). Selecting 127.0.0.1 as default gatway"
+	  DEFAULTGW="127.0.0.1"
+	fi
+	sed -e "s,GW,$DEFAULTGW," $usn/debian/gateway.cfg > $tmpgw
+	chmod 644 $tmpgw
+	ucf --debconf-ok $tmpgw $enc/host-gateway_nagios3.cfg
+
+	# this is where the debconf-ized external command support would go
+	#ucf $usn/debian/extcommands.cfg $enc/extcommands-nagios3.cfg
+
+	# configure the web servers, if it is desired
+	if [ "$servers" ]; then
+		if wc_httpd_apache_include $apacheconf nagios3 $servers; then
+			# reload the selected servers if they are running 
+			running_servers="$(wc_httpd_running $servers)"
+			if [ "$running_servers" ]; then
+				wc_httpd_invoke "reload" $running_servers
+			fi
+		fi	
+	fi
+
+
+	# we reset the password every run, so if it exists we're running
+	# after being specifically given a password and can unconditionally set it.
+	# XXX there's no way of setting the pw w/out giving it on the cmdline? wtf?
+	if [ -n "$admpass" ]; then
+		touch "$htpw"
+		htpasswd -b "$htpw" nagiosadmin "$admpass"
+	fi
+
+	# explicitly set permissions on some files that are dependent
+	# on the uid/gid of the nagios user, which is dynamically created.
+        setperm root nagios 0640 $en/resource.cfg
+        setperm nagios adm 2751 /var/log/nagios3
+        setperm nagios adm 2751 /var/log/nagios3/archives
+        setperm nagios nagios 0750 /var/run/nagios3
+        setperm nagios nagios 0750 /var/lib/nagios3
+	setperm nagios nagios 0750 /var/lib/nagios3/spool
+	setperm nagios nagios 0750 /var/lib/nagios3/spool/checkresults
+        setperm nagios www-data 02750 /var/cache/nagios3
+        setperm nagios www-data 0700 /var/lib/nagios3/rw
+
+	# everything went well, so now let's reset the password
+	db_set nagios3/adminpassword ""
+	db_set nagios3/adminpassword-repeat ""
+	# ... done with debconf here
+	db_stop
+    ;;
+  abort-upgrade|abort-remove|abort-deconfigure)
+    ;;
+  *)
+    echo "postinst called with unknown argument \$1'" >&2
+    exit 1
+    ;;
+esac
+
+#DEBHELPER#

Added: nagios3/trunk/debian/nagios3-cgi.postrm
===================================================================
--- nagios3/trunk/debian/nagios3-cgi.postrm	                        (rev 0)
+++ nagios3/trunk/debian/nagios3-cgi.postrm	2009-09-05 13:59:36 UTC (rev 1748)
@@ -0,0 +1,20 @@
+#!/bin/sh -e
+
+# some shorthands for sanity
+en="/etc/nagios3"
+enc="/etc/nagios3/conf.d"
+usn="/usr/share/nagios3"
+
+case "$1" in
+  remove)
+  	;;
+  purge)
+	rm -f /etc/nagios3/htpasswd.users
+	rm -f /etc/nagios3/apache2.conf
+	if which ucf >/dev/null 2>&1; then
+		ucf --purge /etc/nagios3/apache2.conf
+	fi
+    ;;
+esac
+
+#DEBHELPER#

Added: nagios3/trunk/debian/nagios3-cgi.prerm
===================================================================
--- nagios3/trunk/debian/nagios3-cgi.prerm	                        (rev 0)
+++ nagios3/trunk/debian/nagios3-cgi.prerm	2009-09-05 13:59:36 UTC (rev 1748)
@@ -0,0 +1,25 @@
+#!/bin/sh -e
+
+. /usr/share/nagios3/debian/httpd.webapps-common
+
+apacheconf="/etc/nagios3/apache2.conf"
+
+if [ -f $apacheconf ]; then
+  case "$1" in
+    remove)
+	# find the configured servers
+	configured_servers=`wc_httpd_apache_configured $apacheconf nagios3`
+	if [ "$configured_servers" ]; then
+		# deconfigure them
+		wc_httpd_apache_uninclude $apacheconf nagios3 $configured_servers
+		# reload the configured servers if they are running 
+		running_servers="`wc_httpd_running $configured_servers`"
+		if [ "$running_servers" ]; then
+			wc_httpd_invoke "reload" $running_servers
+		fi
+	fi
+      ;;
+  esac
+fi
+
+#DEBHELPER#




More information about the Pkg-nagios-changes mailing list