]> granicus.if.org Git - icinga2/blob - debian/icinga2-common.postinst
Update Debian package.
[icinga2] / debian / icinga2-common.postinst
1 #!/bin/sh
2 # postinst script for icinga2-common
3
4 set -e
5
6 setperm() {
7     user="$1"
8     group="$2"
9     mode="$3"
10     file="$4"
11     shift 4
12     # only do something when no setting exists
13     if ! dpkg-statoverride --list "$file" >/dev/null 2>&1; then
14       chown "$user":"$group" "$file"
15       chmod "$mode" "$file"
16     fi
17 }
18
19 is_fresh_install()
20 {
21     if [ -z "$2" ] ; then
22         return 0
23     fi
24     return 1
25 }
26
27 enable_default_features() {
28     FIX_VERSION="0.0.5+icingasnap201312070000"
29     if is_fresh_install $@ \
30        || dpkg --compare-versions "$2" lt "$FIX_VERSION"; then
31         echo "enabling default icinga2 features"
32         for feature in checker notification mainlog; do
33             icinga2-enable-feature $feature
34         done
35     fi
36     # handle new default features here in the future
37 }
38
39 case "$1" in
40     configure)
41         if ! getent passwd nagios > /dev/null ; then
42             echo 'Adding system-user for nagios' 1>&2
43             adduser --system --group --home /var/lib/nagios \
44                     --disabled-login --force-badname nagios > /dev/null
45         fi
46
47         # explicitly set permissions on some files that are dependent
48         # on the uid/gid of the nagios user, which is dynamically created.
49         setperm nagios adm 2751 /var/log/icinga2
50         setperm nagios adm 2751 /var/log/icinga2/compat
51         setperm nagios adm 2755 /var/log/icinga2/compat/archives
52
53         setperm nagios nagios 0750 /var/lib/icinga2
54         setperm nagios nagios 0750 /var/lib/icinga2/api
55         setperm nagios nagios 0750 /var/lib/icinga2/api/log
56         setperm nagios nagios 0750 /var/lib/icinga2/api/repository
57
58         setperm nagios www-data 0750 /var/cache/icinga2
59
60         setperm nagios nagios 0750 /var/spool/icinga2
61         setperm nagios nagios 0750 /var/spool/icinga2/perfdata
62         setperm nagios nagios 0750 /var/spool/icinga2/tmp
63
64         # enable default features
65         enable_default_features $@
66     ;;
67
68     abort-upgrade|abort-remove|abort-deconfigure)
69     ;;
70
71     *)
72         echo "postinst called with unknown argument \`$1'" >&2
73         exit 1
74     ;;
75 esac
76
77 init_failed ()
78 {
79     echo "Icinga 2 was unable to start due to configuration errors.";
80     echo "Please fix them and manually restart the icinga2 daemon using";
81     echo " ´service icinga2 start´";
82 }
83
84 #DEBHELPER#
85
86 exit 0