]> granicus.if.org Git - icinga2/blob - debian/icinga2-common.postinst
Remove the migrate-hosts script
[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         icinga2 feature enable checker notification mainlog
33     fi
34     # handle new default features here in the future
35 }
36
37 case "$1" in
38     configure)
39         if ! getent passwd nagios > /dev/null ; then
40             echo 'Adding system-user for nagios' 1>&2
41             adduser --system --group --home /var/lib/nagios \
42                     --disabled-login --force-badname nagios > /dev/null
43         fi
44
45         # explicitly set permissions on some files that are dependent
46         # on the uid/gid of the nagios user, which is dynamically created.
47         setperm nagios nagios 0750 /etc/icinga2
48
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         setperm nagios nagios 0750 /var/lib/icinga2/api/zones
58
59         setperm nagios www-data 0750 /var/cache/icinga2
60
61         setperm nagios nagios 0750 /var/spool/icinga2
62         setperm nagios nagios 0750 /var/spool/icinga2/perfdata
63         setperm nagios nagios 0750 /var/spool/icinga2/tmp
64
65         # enable default features
66         enable_default_features $@
67     ;;
68
69     abort-upgrade|abort-remove|abort-deconfigure)
70     ;;
71
72     *)
73         echo "postinst called with unknown argument \`$1'" >&2
74         exit 1
75     ;;
76 esac
77
78 init_failed ()
79 {
80     echo "Icinga 2 was unable to start due to configuration errors.";
81     echo "Please fix them and manually restart the icinga2 daemon using";
82     echo " ´service icinga2 start´";
83 }
84
85 #DEBHELPER#
86
87 exit 0