summaryrefslogtreecommitdiff
path: root/debian/webapps-config
blob: d9b02664e6be92dcf82960d4e79999bd9e8009bc (plain)
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
# some library functions for phpbb3 maintainer scripts
# copyright 2010 J.M. Roth <jmroth@iip.lu>

get_webserver_configdata () {
    local package=$1
    local webserver=$2
    local prio=$3

    case "$webserver" in
        "lighttpd" )
            confdir=conf-available
            wfile=${prio}-$package.conf
            ;;
        "apache2" )
            confdir=conf-available
            wfile=$package.conf
            ;;
        * )
            echo "$0 $@: webserver $webserver is not supported." 1>&2
            return 1
            ;;
    esac
}

# picked up from https://wiki.debian.org/Apache/PackagingFor24#Making_web_applications_compatible_to_both.2C_Apache_2.2_and_2.4
COMMON_STATE=$(dpkg-query -f '${Status}' -W 'apache2.2-common' 2>/dev/null | awk '{print $3}' || true)
APACHE2_MAINTSCRIPT_METHOD=$1
APACHE2_MAINTSCRIPT_ARGUMENT=$2

install_webserver_config () {
    local package=$1
    local webserver=$2
    local prio=$3

    get_webserver_configdata $@ || return 1
    # yields: $confdir, $wfile

    if [ -d /etc/$webserver/$confdir ] && [ ! -L /etc/$webserver/$confdir/$wfile ] ; then
        if [ ! -x /usr/sbin/$webserver ] ; then
            echo "$0 $@: webserver $webserver not found, skipping" 1>&2
        else
            ln -s ../../$package/$webserver.conf /etc/$webserver/$confdir/$wfile
            if [ "$webserver" = "lighttpd" ] ; then
                lighty-enable-mod $package >/dev/null
            elif [ "$webserver" = "apache2" ] ; then
		if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
		    . /usr/share/apache2/apache2-maintscript-helper
		    apache2_invoke enconf $package
		elif [ "$COMMON_STATE" = "installed" ] || [ "$COMMON_STATE" = "unpacked" ] ; then
		    [ -d /etc/apache2/conf.d/ ] && [ ! -L /etc/apache2/conf.d/$package.conf ] && ln -s ../conf-available/$package.conf /etc/apache2/conf.d/$package.conf
		fi
            fi
        fi
    fi
}

_purge_webserver_config () {
    local package=$1
    local webserver=$2
    local prio=$3

    get_webserver_configdata $@ || return 0
    # yields: $confdir, $wfile

    if [ -d /etc/$webserver/$confdir ] && [ -L /etc/$webserver/$confdir/$wfile ] ; then
        if [ ! -x /usr/sbin/$webserver ] ; then
            echo "$0 $@: webserver $webserver not installed, skipping" 1>&2
        else
            if [ "$webserver" = "lighttpd" ] ; then
                lighty-disable-mod $package >/dev/null
            elif [ "$webserver" = "apache2" ] ; then
		if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
		    . /usr/share/apache2/apache2-maintscript-helper
		    apache2_invoke disconf $package
		elif [ "$COMMON_STATE" = "installed" ] || [ "$COMMON_STATE" = "unpacked" ] ; then
		    [ -L /etc/apache2/conf.d/$package.conf ] && rm /etc/apache2/conf.d/$package.conf
		fi
            fi
            rm /etc/$webserver/$confdir/$wfile
        fi
    fi
}

purge_webserver_config () {
    local package=$1
    local webserver=$2
    local prio=$3

    case "$webserver" in
        "all" )
            db_metaget $package/httpd Choices
            for w in $RET ; do
                _purge_webserver_config $package ${w%,} $prio
            done
            ;;
        * )
            _purge_webserver_config $@
            ;;
    esac
}

_reload_webserver () {
    local webserver=$1

    if [ -x /usr/sbin/$webserver ]; then
	# Redirection of fd 3 is needed because Debconf uses it and it might
	# be inherited by webserver. See bug #446324.
        if [ -x /usr/sbin/invoke-rc.d ]; then
            invoke-rc.d $webserver reload 3>/dev/null || true
        else
            /etc/init.d/$webserver reload 3>/dev/null || true
        fi
        echo
    fi
}

reload_webserver () {
    local package=$1
    local webserver=$2

    case "$webserver" in
        "all" )
            db_metaget $package/httpd Choices
            for w in $RET ; do
                _reload_webserver ${w%,}
            done
            ;;
        * )
            _reload_webserver ${webserver%,}
            ;;
    esac
}