This file is indexed.

postinst is in icinga2-classicui 2.4.1-2ubuntu1.

This file is a maintainer script. It is executed when installing (*inst) or removing (*rm) the package.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/sh
# postinst script for icinga2-classicui

set -e

. /usr/share/debconf/confmodule

# shorthand
en="/etc/icinga2-classicui"

# 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
}

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"
        icinga2 feature enable compatlog statusdata command

        echo "reloading icinga2"
        [ -x $(which invoke-rc.d) ] && invoke-rc.d icinga2 reload
    fi
    # handle new default features here in the future
}

case "$1" in
    configure)
        enable_features_for_classic $@

        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

        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

            apache2_invoke enmod cgi
            apache2_invoke enconf icinga2-classicui

        # OLD methods for Apache < 2.4
        elif [ "$COMMON_STATE" = "installed" ] || [ "$COMMON_STATE" = "unpacked" ] ; then
            a2enmod cgi
            # create symlink if not existing
            [ -e /etc/apache2/conf.d/icinga2-classicui.conf ] || ln -vs $en/apache2.conf /etc/apache2/conf.d/icinga2-classicui.conf

            # reload webserver
            [ -x $(which invoke-rc.d) ] && invoke-rc.d apache2 reload
        fi

        # check for an old symlink to the stylesheets
        test -L /etc/icinga2/classicui/stylesheets && rm \
        /etc/icinga2/classicui/stylesheets && rmdir /etc/icinga2/classicui || true 
        ###
        # 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
                echo "$admpass" | htpasswd -i "$htpw" icingaadmin
            else
                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´";
}



exit 0