Code

npcdmod.cfg: Fixed a few typos and improved wording.
[pkg-pnp4nagios.git] / debian / pnp4nagios-web.postinst
1 #!/bin/sh
2 # postinst script for pnp4nagios-web
3 #
4 # see: dh_installdeb(1)
6 set -e
8 # summary of how this script can be called:
9 #        * <postinst> `configure' <most-recently-configured-version>
10 #        * <old-postinst> `abort-upgrade' <new version>
11 #        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
12 #          <new-version>
13 #        * <postinst> `abort-remove'
14 #        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
15 #          <failed-install-package> <version> `removing'
16 #          <conflicting-package> <version>
17 # for details, see http://www.debian.org/doc/debian-policy/ or
18 # the debian-policy package
20 . /usr/share/debconf/confmodule
22 setperm() {
23         user="$1"
24         group="$2"
25         mode="$3"
26         file="$4"
27         shift 4
28         # only do something when no setting exists
29         if ! dpkg-statoverride --list "$file" >/dev/null 2>&1; then
30                 chown "$user":"$group" "$file"
31                 chmod "$mode" "$file"
32         fi
33 }
35 configure_apache2() {
36         a2reload="false"
38         if [ -d /etc/apache2/conf.d/ ]; then
39                 if [ ! -e /etc/apache2/conf.d/pnp4nagios.conf ]; then
40                         ln -s /etc/pnp4nagios/apache.conf /etc/apache2/conf.d/pnp4nagios.conf
41                         a2reload="true"
42                 fi
43         fi
45         if [ -d /etc/apache2/mods-enabled ]; then
46                 if [ ! -e /etc/apache2/mods-enabled/rewrite.load ]; then
47                         if [ -x /usr/sbin/a2enmod ]; then
48                                 a2enmod rewrite
49                                 a2reload="true"
50                         fi
51                 fi
52         fi
54         if [ "$a2reload" = "true" ]; then
55                 if [ -x /etc/init.d/apache2 ]; then
56                         invoke-rc.d apache2 reload
57                 fi
58         fi
59 }
61 case "$1" in
62         configure)
63                 if ! getent passwd nagios > /dev/null ; then
64                         echo 'Adding system-user for nagios' 1>&2
65                         adduser --system --group --home /var/lib/nagios \
66                                 --disabled-login --force-badname nagios > /dev/null
67                 fi
68                 setperm nagios www-data 750 /var/lib/pnp4nagios
69                 setperm nagios nagios   755 /var/lib/pnp4nagios/perfdata
70                 setperm nagios www-data 750 /var/log/pnp4nagios
72                 db_get pnp4nagios-web/httpd
73                 http_servers=`echo $RET | sed -e 's/,/ /g'`
75                 for httpd in $http_servers; do
76                         case "$httpd" in
77                                 apache2)
78                                         configure_apache2
79                                         ;;
80                                 # WISHLIST: configure other web servers as well
81                                 *)
82                                         echo "Don't know how to configure web server $httpd" >&2
83                                         ;;
84                         esac
85                 done
86         ;;
88         abort-upgrade|abort-remove|abort-deconfigure)
89         ;;
91         *)
92                 echo "postinst called with unknown argument \`$1'" >&2
93                 exit 1
94         ;;
95 esac
97 # dh_installdeb will replace this with shell code automatically
98 # generated by other debhelper scripts.
100 #DEBHELPER#
102 exit 0