pkg://nagios-common_1.3-cvs.20050402-2.sarge.2_all.deb:1219662/postinst
info downloads
#! /bin/sh
# postinst script for nagios
#
# see: dh_installdeb(1)
set -e
# Source debconf library.
. /usr/share/debconf/confmodule
# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see /usr/doc/packaging-manual/
#
# quoting from the policy:
# Any necessary prompting should almost always be confined to the
# post-installation script, and should be protected with a conditional
# so that unnecessary prompting doesn't happen if a package's
# installation fails and the `postinst' is called with `abort-upgrade',
# `abort-remove' or `abort-deconfigure'.
# Restart apache/apache-ssl
restartapache () {
if [ -x "/etc/init.d/apache2" ]; then
invoke-rc.d apache2 reload || true
else
for apache in $webservers; do
if [ -x "/etc/init.d/$apache" ]; then
invoke-rc.d $apache reload || true
fi
done
fi
}
# Automatic Apache Configuration:
configapache () {
removeoldapache
for apache in $webservers; do
if [ -d "/etc/$apache/conf.d" -a ! -e "/etc/$apache/conf.d/nagios" ]; then
ln -s /etc/nagios/apache.conf /etc/$apache/conf.d/nagios
fi
done
restartapache
}
# Remove old entries in httpd.conf
removeoldapache () {
for apache in $webservers; do
if [ "$apache" = "apache2" ]; then
conf=apache2.conf
else
conf=httpd.conf
fi
# XXX this is a temporary hack, this all needs to be reworked
if [ -f "/etc/$apache/$conf" ]; then
if grep -qs "^Include /etc/nagios/apache.conf" /etc/$apache/$conf; then
mv -f /etc/$apache/$conf /etc/$apache/$conf.old.nagios
grep -v "^Include /etc/nagios/apache.conf" /etc/$apache/$conf.old.nagios \
> /etc/$apache/$conf
fi
if ! grep -qs "^Include /etc/$apache/conf.d" /etc/$apache/$conf; then
cp -f /etc/$apache/$conf /etc/$apache/$conf.old.nagios
echo "Include /etc/$apache/conf.d" >> /etc/$apache/$conf
fi
if [ -f /etc/$apache/$conf.old.nagios ]; then
mv -f /etc/$apache/$conf.old.nagios /etc/$apache/$conf.old
fi
fi
done
}
# Do postinst
case "$1" in
configure|upgrade)
# Apache/Apache-SSL location. Apache2 is overwritten below
htpasswd="/usr/bin/htpasswd"
db_get nagios/configapache
webserver="$RET"
case "$webserver" in
Apache) webservers="apache";;
Apache2) webservers="apache2" ; htpasswd="/usr/bin/htpasswd2";;
Apache-SSL) webservers="apache-ssl";;
Both) webservers="apache apache-ssl";;
*) webservers="";;
esac
if [ -e "/usr/bin/htpasswd-caudium" -a -z "$webservers" ]; then
htpasswd="/usr/bin/htpasswd-caudium"
fi
if [ ! -z "$webservers" ]; then
configapache
fi
if [ -e "$htpasswd" ]; then
db_get nagios/adminpassword
if [ -z "$RET" ]; then
echo "Not setting blank password for nagiosadmin"
elif [ ! -f /etc/nagios/htpasswd.users ] ; then
# The passwd file don't exists
$htpasswd -c -b /etc/nagios/htpasswd.users nagiosadmin "$RET"
else
echo "Nagiosadmin already existing with password. To change the"
echo "password, please use the $htpasswd command."
fi
else
cat <<EOF
There is no htpasswd command, so I can't create the password file
for you. If you want to use nagios with apache You will have to figure
out a way to create a htpasswd file yourself. If you've chosen
to configure apache (or some other web server) manually, you can safely
disregard this. Otherwise, the htpasswd file should be called:
/etc/nagios/htpasswd.users
and be mode 0640, owned by root, group www-data.
chown root:www-data /etc/nagios/htpasswd.users
chmod 0640 /etc/nagios/htpasswd.users
EOF
fi
db_get nagios/wwwsuid
if [ "$RET" = "true" ] ; then
chown nagios /usr/lib/cgi-bin/nagios/*cgi
chmod u+s /usr/lib/cgi-bin/nagios/*cgi
for f in /usr/lib/cgi-bin/nagios/*.cgi; do
if ! dpkg-statoverride --list "$f" >/dev/null; then
dpkg-statoverride --add nagios root 4755 "$f"
fi
done
perl -wpi -e 's[^check_external_commands=0][check_external_commands=1]' /etc/nagios/nagios.cfg
else
chmod u-s /usr/lib/cgi-bin/nagios/*cgi
for f in /usr/lib/cgi-bin/nagios/*.cgi; do
if dpkg-statoverride --list "$f" >/dev/null; then
dpkg-statoverride --remove "$f"
fi
done
perl -wpi -e 's[^check_external_commands=1][check_external_commands=0]' /etc/nagios/nagios.cfg
fi
# We are finished with debconf
db_stop
if [ -f /etc/nagios/htpasswd.users ]; then
# Make sure some files aren't world readable, may contain sensitive information
chmod 640 /etc/nagios/htpasswd.users /etc/nagios/cgi.cfg /etc/nagios/resource.cfg
chgrp www-data /etc/nagios/htpasswd.users
fi
UDIR=/usr/share/nagios ; EDIR=/etc/nagios
## Conf files have moved:
for f in `find $UDIR/robots.txt $UDIR/*html 2> /dev/null`; do
if [ -f $f -a ! -L $f ] ; then
mv -f $f /etc/nagios/
fi
done
## Sym links for conf files:
for f in `find $EDIR/robots.txt $EDIR/*html 2> /dev/null`; do
if [ ! -e /usr/share/nagios/htdocs/`basename $f` ] ; then
ln -s $f /usr/share/nagios/htdocs/
fi
done
for s in `find $UDIR/index.html $UDIR/main.html $UDIR/side.html $UDIR/robots.txt 2> /dev/null`; do
if [ ! -h $s ] ; then
rm -f $s
fi
done
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 0
;;
esac
# Setup the address to the default gateway
if [ ! -f /etc/nagios/hosts.cfg ]; then
set -- `route -n | grep '^0.0.0.0' | head -n1`
DEFAULTGW=$2
TMPFILE=`tempfile -p nag.`
zcat /usr/share/doc/nagios-common/examples/template-object/hosts.cfg.gz | sed "s/@DEFAULT_GW@/$DEFAULTGW/" > $TMPFILE
mv $TMPFILE /etc/nagios/hosts.cfg
fi
if [ ! -L /usr/lib/nagios/plugins/check_nagios -a \
! -f /usr/lib/nagios/plugins/check_nagios -a \
-e /usr/lib/nagios/plugins/check_netsaint ]
then
(cd /usr/lib/nagios/plugins ; \
ln -s /usr/lib/nagios/plugins/check_netsaint check_nagios)
fi
# Make sure the config file is readable by both nagios
# and apache
chown -R nagios:www-data /var/log/nagios /etc/nagios /var/run/nagios /var/cache/nagios
chmod 750 /etc/nagios/cgi.cfg
# Automatically added by dh_installinit
if [ -x "/etc/init.d/nagios" ]; then
update-rc.d nagios defaults 30 >/dev/null
if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
invoke-rc.d nagios start || exit 0
else
/etc/init.d/nagios start || exit 0
fi
fi
# End automatically added section