]> granicus.if.org Git - icinga2/blob - debian/icinga2-classicui.postinst
Don't disable notifications on master instances.
[icinga2] / debian / icinga2-classicui.postinst
1 #!/bin/sh
2 # postinst script for icinga2-classicui
3
4 set -e
5
6 . /usr/share/debconf/confmodule
7
8 # shorthand
9 en="/etc/icinga2/classicui"
10
11 # location of the default apache configuration for icinga
12 apacheconf=$en/apache2.conf
13 # location of the default htpasswd authentication file.
14 htpw=$en/htpasswd.users
15
16 setperm() {
17     user="$1"
18     group="$2"
19     mode="$3"
20     file="$4"
21     shift 4
22     # only do something when no setting exists
23     if ! dpkg-statoverride --list "$file" >/dev/null 2>&1; then
24       chown "$user":"$group" "$file"
25       chmod "$mode" "$file"
26     fi
27 }
28
29 is_fresh_install()
30 {
31     if [ -z "$2" ] ; then
32         return 0
33     fi
34     return 1
35 }
36
37 enable_features_for_classic() {
38     if is_fresh_install $@; then
39         echo "enabling icinga2 features for classicui"
40
41         for feature in compatlog statusdata command; do
42             icinga2-enable-feature $feature
43         done
44
45         echo "reloading icinga2"
46         [ -x $(which invoke-rc.d) ] && invoke-rc.d icinga2 reload
47     fi
48     # handle new default features here in the future
49 }
50
51 case "$1" in
52     configure)
53         enable_features_for_classic $@
54
55         echo "enabling Apache2 config..."
56         COMMON_STATE=$(dpkg-query -f '${Status}' -W 'apache2.2-common' 2>/dev/null | awk '{print $3}' || true)
57
58         # NEW method for Apache >= 2.4
59         if [ -e /usr/share/apache2/apache2-maintscript-helper ]; then
60             . /usr/share/apache2/apache2-maintscript-helper
61
62             apache2_invoke enconf icinga2-classicui
63
64         # OLD methods for Apache < 2.4
65         elif [ "$COMMON_STATE" = "installed" ] || [ "$COMMON_STATE" = "unpacked" ] ; then
66             # create symlink if not existing
67             [ -f /etc/apache2/conf.d/icinga2-classicui.conf ] || ln -vs ../../icinga2/classicui/apache2.conf /etc/apache2/conf.d/icinga2-classicui.conf
68
69             # reload webserver
70             [ -x $(which invoke-rc.d) ] && invoke-rc.d apache2 reload
71         fi
72
73         ###
74         # Admin password
75         ###
76         db_get icinga2-classicui/adminpassword
77         admpass="$RET"
78
79         test -f "$htpw" || touch "$htpw"
80         setperm root www-data 0640 "$htpw"
81
82         # we reset the password every run, so if it exists we're running
83         # after being specifically given a password and can unconditionally set it.
84         # XXX there's no way of setting the pw w/out giving it on the cmdline? wtf?
85         if [ -n "$admpass" ]; then
86             #unfortunatly that method only works with 2.4
87             if htpasswd 2>&1 | grep -q ' -i'; then
88                 echo "$admpass" | htpasswd -i "$htpw" icingaadmin
89             else
90                 htpasswd -b "$htpw" icingaadmin "$admpass"
91             fi
92         fi
93
94         # everything went well, so now let's reset the password
95         db_set icinga2-classicui/adminpassword ""
96         db_set icinga2-classicui/adminpassword-repeat ""
97         # ... done with debconf here
98         db_stop
99
100     ;;
101
102     abort-upgrade|abort-remove|abort-deconfigure)
103     ;;
104
105     *)
106         echo "postinst called with unknown argument \`$1'" >&2
107         exit 1
108     ;;
109 esac
110
111 init_failed ()
112 {
113     echo "Icinga 2 was unable to start due to configuration errors.";
114     echo "Please fix them and manually restart the icinga2 daemon using";
115     echo " ´service icinga2 start´";
116 }
117
118 #DEBHELPER#
119
120 exit 0