File: httpd.sh

package info (click to toggle)
dhelp 0.6.30
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 592 kB
  • sloc: ruby: 1,171; sh: 555; perl: 372; makefile: 83
file content (267 lines) | stat: -rw-r--r-- 7,103 bytes parent folder | download | duplicates (3)
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# httpd configuration enable/disable functions for Debian maintainer scripts.
# Copyright (C) 2012 Georgios M. Zarkadas <gz@member.fsf.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA  02111-1307  USA.
#
# This file is intended to be sourced by maintainer scripts.

# REQUIRES: info.sh files.sh

# (internal) message template functions

# ARGS:
# $1=package $2=caller
#
_httpdmsg_nocfa()
{
    echo "${1} error: invalid action '${2}' supplied as argument"
}

# ARGS:
# $1=caller_with_args
#
_httpdmsg_nopkg()
{
    echo "${1} error: package name was not supplied as argument"
}

# ARGS:
# $1=package $2=httpd_name $3={enable,disable}
#
_httpdmsg_check()
{
    local text=""
    if [ "${3}" = "disable" ]; then
        text="de"
    fi
    echo "check the status of the ${2} web server and whether" \
        "${1} configuration for ${2} has been ${text}activated."
}

# ARGS:
# $1=package $2=httpd_name $3={enable,disable}
#
_httpdmsg_noact()
{
    local text=""
    if [ "${3}" = "disable" ]; then
        text="de"
    fi
    echo "${1} configuration for ${2} has not been ${text}activated."
}

# Return error if action is not (en/dis)able or package is empty.
# ARGS:
# $1=action $2=package $3=caller
#
_check_action_and_package()
{
    local action=${1}
    local package=${2}
    local caller=${3}

    local nopkg="false"

    if [ "X${package}" = "X" ]; then
        package=unknown
        nopkg="true"
    fi

    case ${action} in
    enable|disable)
        ;;
    *)
        install_msg ${package} err $(_hhtpdmsg_nocfa ${package} ${caller})
        return 10
        ;;
    esac

    if [ "${nopkg}" = "true" ]; then
        install_msg ${package} err $(_httpdmsg_nopkg "${caller} ${action}")
        return 11
    fi

    return 0
}

# Return {new,old,unknown} when, respectively, the apache2 package uses
# new / old packaging or it is not installed in the system.
# ARGS: none
#
apache2_packaging ()
{
    if ! is_pkg_installed 'apache2'; then
        echo 'unknown'
	return
    fi

    local aversion=$(get_pkg_version 'apache2')
    local amajor=$(version_major "${aversion}")
    local aminor=$(version_minor "${aversion}")

    local packaging="old"
    case ${amajor} in
    2)
        if [ ${aminor} -ge 4 ]; then
            packaging="new"
        fi
        ;;
    *)
        if [ ${amajor} -gt 2]; then
            packaging="new"
        fi
        ;;
    esac
    echo ${packaging}
}

# Try to (en/dis)able an apache2 configuration snippet.
# Return error if (en/dis)abling tried and failed; caller *must* check status.
# ARGS:
# $1=maintscript-action (configure,abort-upgrade)
# $2={enable,disable} $3=package [$4=name_of_snippet_if_different_from_package]
#
try_chconf_apache2 ()
{
    local maintscript_action=${1}
    local action=${2}
    local package=${3}
    local confname=${4}

    local ret=0
    _check_action_and_package ${action} ${package} "try_chconf_apache2" \
        && ret=$? || ret=$?
    if [ ${ret} -ne 0 ]; then
        return ${ret}
    fi

    local confaction
    if [ "${action}" = "enable" ]; then
        confaction=enconf
    else
        confaction=disconf
    fi

    if [ "X${confname}" = "X" ]; then
        confname=${package}
    fi

    case $(apache2_packaging) in
    new)
        # The apache2_invoke function also reloads the web server
        # if it is running.

        local ahelper=/usr/share/apache2/apache2-maintscript-helper

        if [ -e $ahelper ] ; then
            . $ahelper $maintscript_action
            apache2_invoke ${confaction} ${confname}.conf && ret=$? || ret=$?
            if [ ${ret} -ne 0 ]; then
                install_msg ${package} warning \
                    "apache2_invoke returned an error;" \
                    $(_httpdmsg_check ${package} apache2 ${action})
            fi
            return ${ret}
        else
            install_msg ${package} warning \
                "apache2-maintscript-helper not found;" \
                $(_httpdmsg_noact ${package} apache2 ${action})
            return 1
        fi
        ;;
    old)
        # The apache2 init script uses apache2ctl configtest internally
        # and also checks that the server is indeed running; thus there
        # is no need to repeat these tests here.

        invoke-rc.d apache2 reload && ret=$? || ret=$?
        if [ ${ret} -ne 0 ]; then
            install_msg ${package} warning \
                "invoke-rc.d apache2 returned an error;" \
                $(_httpdmsg_check ${package} apache2 ${action})
        fi
        return ${ret}
        ;;
    *)  # can only be unknown in which case apache2 is not installed; return
        ;;
    esac
}

# Try to (en/dis)able a lighttpd configuration snippet.
# Return error if (en/dis)abling tried and failed; caller *must* check status.
# ARGS:
# $1=maintscript-action (configure,abort-upgrade), not used
# $2={enable,disable} $3=package [$4=name_of_snippet_if_different_from_package]
#
try_chconf_lighttpd ()
{
    local maintscript_action=${1}
    local action=${2}
    local package=${3}
    local snippetname=${4}

    local ret=0
    _check_action_and_package ${action} ${package} "try_chconf_lighttpd" \
        && ret=$? || ret=$?
    if [ ${ret} -ne 0 ]; then
        return ${ret}
    fi

    local confaction
    if [ "${action}" = "enable" ]; then
        confaction=lighty-enable-mod
    else
        confaction=lighty-disable-mod
    fi

    if ! is_pkg_installed 'lighttpd'; then
        return 0
    fi

    local confname=${package}

    if [ "X${snippetname}" != "X" ]; then
        confname=${snippetname}
    fi

    # lighty-xxx-mod will return 2 if no action is needed; workaround this.

    if is_exec ${confaction}; then
        ${confaction} ${confname} && ret=$? || ret=$?
        if [ $ret -eq 1 ]; then
            install_msg ${package} warning \
                "${confaction} returned an error;" \
                $(_httpdmsg_noact ${package} lighttpd ${action})
            return 1
        fi
    else
        install_msg ${package} warning \
            "${confaction} not found;" \
            $(_httpdmsg_noact ${package} lighttpd ${action})
        return 2
    fi

    # Try to reload the web server configuration.

    invoke-rc.d lighttpd reload && ret=$? || ret=$?
    if [ ${ret} -ne 0 ]; then
        install_msg ${package} warning \
            "invoke-rc.d lighttpd returned an error;" \
            $(_httpdmsg_check ${package} lighttpd ${action})
    fi
    return ${ret}
}