2013-11-01 21:35:55 +01:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
# postinst script for icinga2-classicui
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
. /usr/share/debconf/confmodule
|
|
|
|
|
|
|
|
|
|
# shorthand
|
2014-12-18 06:12:26 +01:00
|
|
|
|
en="/etc/icinga2-classicui"
|
2013-11-01 21:35:55 +01:00
|
|
|
|
|
|
|
|
|
# location of the default apache configuration for icinga
|
|
|
|
|
apacheconf=$en/apache2.conf
|
|
|
|
|
# location of the default htpasswd authentication file.
|
|
|
|
|
htpw=$en/htpasswd.users
|
|
|
|
|
|
|
|
|
|
setperm() {
|
|
|
|
|
user="$1"
|
|
|
|
|
group="$2"
|
|
|
|
|
mode="$3"
|
|
|
|
|
file="$4"
|
|
|
|
|
shift 4
|
|
|
|
|
# only do something when no setting exists
|
|
|
|
|
if ! dpkg-statoverride --list "$file" >/dev/null 2>&1; then
|
|
|
|
|
chown "$user":"$group" "$file"
|
|
|
|
|
chmod "$mode" "$file"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-04 19:06:43 +01:00
|
|
|
|
is_fresh_install()
|
|
|
|
|
{
|
|
|
|
|
if [ -z "$2" ] ; then
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enable_features_for_classic() {
|
|
|
|
|
if is_fresh_install $@; then
|
|
|
|
|
echo "enabling icinga2 features for classicui"
|
2014-10-14 18:32:15 +02:00
|
|
|
|
icinga2 feature enable compatlog statusdata command
|
2013-12-04 19:06:43 +01:00
|
|
|
|
|
|
|
|
|
echo "reloading icinga2"
|
|
|
|
|
[ -x $(which invoke-rc.d) ] && invoke-rc.d icinga2 reload
|
|
|
|
|
fi
|
|
|
|
|
# handle new default features here in the future
|
|
|
|
|
}
|
2013-11-01 21:35:55 +01:00
|
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
|
configure)
|
2013-12-04 19:06:43 +01:00
|
|
|
|
enable_features_for_classic $@
|
2013-11-01 21:35:55 +01:00
|
|
|
|
|
2014-12-18 06:12:26 +01:00
|
|
|
|
dpkg-maintscript-helper mv_conffile \
|
|
|
|
|
/etc/icinga2/classicui/apache2.conf \
|
|
|
|
|
/etc/icinga2-classicui/apache2.conf 2.2.0-1~ icinga2-classicui -- "$@"
|
|
|
|
|
|
|
|
|
|
dpkg-maintscript-helper mv_conffile /etc/icinga2/classicui/cgi.cfg \
|
|
|
|
|
/etc/icinga2-classicui/cgi.cfg 2.2.0-1~ icinga2-classicui -- "$@"
|
|
|
|
|
|
|
|
|
|
if [ -f '/etc/icinga2/classicui/htpasswd.users' ] && [ ! -f '/etc/icinga2-classicui/htpasswd.users' ];
|
|
|
|
|
then
|
|
|
|
|
echo "Move classicui password file to new location"
|
|
|
|
|
mv -f /etc/icinga2/classicui/htpasswd.users \
|
|
|
|
|
/etc/icinga2-classicui/htpasswd.users
|
|
|
|
|
rmdir /etc/icinga2/classicui || true
|
|
|
|
|
fi
|
|
|
|
|
|
2013-11-01 21:35:55 +01:00
|
|
|
|
echo "enabling Apache2 config..."
|
|
|
|
|
COMMON_STATE=$(dpkg-query -f '${Status}' -W 'apache2.2-common' 2>/dev/null | awk '{print $3}' || true)
|
|
|
|
|
|
|
|
|
|
# NEW method for Apache >= 2.4
|
|
|
|
|
if [ -e /usr/share/apache2/apache2-maintscript-helper ]; then
|
|
|
|
|
. /usr/share/apache2/apache2-maintscript-helper
|
|
|
|
|
|
2014-07-23 18:57:33 +02:00
|
|
|
|
apache2_invoke enmod cgi
|
2013-11-01 21:35:55 +01:00
|
|
|
|
apache2_invoke enconf icinga2-classicui
|
|
|
|
|
|
|
|
|
|
# OLD methods for Apache < 2.4
|
|
|
|
|
elif [ "$COMMON_STATE" = "installed" ] || [ "$COMMON_STATE" = "unpacked" ] ; then
|
2014-07-23 18:57:33 +02:00
|
|
|
|
a2enmod cgi
|
2013-11-01 21:35:55 +01:00
|
|
|
|
# create symlink if not existing
|
2014-12-18 06:12:26 +01:00
|
|
|
|
[ -e /etc/apache2/conf.d/icinga2-classicui.conf ] || ln -vs $en/apache2.conf /etc/apache2/conf.d/icinga2-classicui.conf
|
2013-11-01 21:35:55 +01:00
|
|
|
|
|
|
|
|
|
# reload webserver
|
|
|
|
|
[ -x $(which invoke-rc.d) ] && invoke-rc.d apache2 reload
|
|
|
|
|
fi
|
|
|
|
|
|
2014-12-18 06:12:26 +01:00
|
|
|
|
# check for an old symlink to the stylesheets
|
|
|
|
|
test -L /etc/icinga2/classicui/stylesheets && rm \
|
|
|
|
|
/etc/icinga2/classicui/stylesheets && rmdir /etc/icinga2/classicui || true
|
2013-11-01 21:35:55 +01:00
|
|
|
|
###
|
|
|
|
|
# Admin password
|
|
|
|
|
###
|
|
|
|
|
db_get icinga2-classicui/adminpassword
|
|
|
|
|
admpass="$RET"
|
|
|
|
|
|
|
|
|
|
test -f "$htpw" || touch "$htpw"
|
|
|
|
|
setperm root www-data 0640 "$htpw"
|
|
|
|
|
|
|
|
|
|
# we reset the password every run, so if it exists we're running
|
|
|
|
|
# after being specifically given a password and can unconditionally set it.
|
|
|
|
|
# XXX there's no way of setting the pw w/out giving it on the cmdline? wtf?
|
|
|
|
|
if [ -n "$admpass" ]; then
|
|
|
|
|
#unfortunatly that method only works with 2.4
|
|
|
|
|
if htpasswd 2>&1 | grep -q ' -i'; then
|
2014-12-18 06:12:26 +01:00
|
|
|
|
echo "$admpass to $htpw"
|
2013-11-01 21:35:55 +01:00
|
|
|
|
echo "$admpass" | htpasswd -i "$htpw" icingaadmin
|
|
|
|
|
else
|
2014-12-18 06:12:26 +01:00
|
|
|
|
echo "$admpass to $htpw"
|
2013-11-01 21:35:55 +01:00
|
|
|
|
htpasswd -b "$htpw" icingaadmin "$admpass"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# everything went well, so now let's reset the password
|
|
|
|
|
db_set icinga2-classicui/adminpassword ""
|
|
|
|
|
db_set icinga2-classicui/adminpassword-repeat ""
|
|
|
|
|
# ... done with debconf here
|
|
|
|
|
db_stop
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
abort-upgrade|abort-remove|abort-deconfigure)
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
*)
|
|
|
|
|
echo "postinst called with unknown argument \`$1'" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
init_failed ()
|
|
|
|
|
{
|
|
|
|
|
echo "Icinga 2 was unable to start due to configuration errors.";
|
|
|
|
|
echo "Please fix them and manually restart the icinga2 daemon using";
|
|
|
|
|
echo " ´service icinga2 start´";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#DEBHELPER#
|
|
|
|
|
|
|
|
|
|
exit 0
|