Debian Codegraph @

debian/nagios4-cgi.postinst

raw
1 #!/bin/bash
2
3 set -e
4
5 # debconf-devel(7) asks we do this
6 . /usr/share/debconf/confmodule
7
8 # some shorthands for sanity
9 en="/etc/nagios4"
10 enc="/etc/nagios4/conf.d"
11 usn="/usr/share/nagios4"
12
13 # location of the default apache configuration for nagios.
14 apache2conf="${en}/apache2.conf"
15 # location of the default htdigest authentication file.
16 htdigest="${en}/htdigest.users"
17
18 setperm() {
19 local user="${1}"
20 local group="${2}"
21 local mode="${3}"
22 local file="${4}"
23 shift 4
24 # only do something when no setting exists
25 if ! dpkg-statoverride --list "${file}" >/dev/null 2>&1
26 then
27 if [ -e "${file}" ]
28 then
29 chown "${user}":"${group}" "${file}"
30 chmod "${mode}" "${file}"
31 fi
32 fi
33 }
34
35 case "${1}" in
36 configure)
37 if ! getent passwd nagios > /dev/null
38 then
39 echo 'Adding system-user for nagios' 1>&2
40 adduser \
41 --system --group --home /var/lib/nagios \
42 --disabled-login --force-badname nagios > /dev/null
43 fi
44
45 # register apache2.conf via ucf:
46 ucf --debconf-ok /usr/share/nagios4/apache2.conf "${apache2conf}"
47
48 # apache2.conf uses this file
49 if [ ! -e "${htdigest}" ]
50 then
51 touch "${htdigest}"
52 setperm nagios www-data 0640 "${htdigest}"
53 fi
54
55 echo "enabling Apache2 config..."
56
57 if [ -e /var/lib/nagios4/rw ]
58 then
59 setperm nagios www-data 0750 /var/lib/nagios4
60 setperm nagios www-data 2710 /var/lib/nagios4/rw
61 fi
62
63 if [ -e /usr/share/apache2/apache2-maintscript-helper ]
64 then (
65 . /usr/share/apache2/apache2-maintscript-helper
66 apache2_invoke enmod auth_digest
67 apache2_invoke enmod authz_groupfile
68 ) fi
69 ;;
70 abort-upgrade|abort-remove|abort-deconfigure)
71 ;;
72 *)
73 echo "postinst called with unknown argument '${1}'" >&2
74 exit 1
75 ;;
76 esac
77
78 #DEBHELPER#