summaryrefslogtreecommitdiffstats
path: root/debian/debhelper
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 06:33:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 06:33:51 +0000
commit4f0770f3df78ecd5dcaefbd214f7a1415366bca6 (patch)
tree72661b8f81594b855bcc967b819263f63fa30e17 /debian/debhelper
parentAdding upstream version 2.4.56. (diff)
downloadapache2-4f0770f3df78ecd5dcaefbd214f7a1415366bca6.tar.xz
apache2-4f0770f3df78ecd5dcaefbd214f7a1415366bca6.zip
Adding debian version 2.4.56-1~deb11u2.debian/2.4.56-1_deb11u2debian
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--debian/debhelper/apache2-maintscript-helper506
-rw-r--r--debian/debhelper/apache2.pm8
-rwxr-xr-xdebian/debhelper/dh_apache2.in582
-rw-r--r--debian/debhelper/postinst-apache28
-rw-r--r--debian/debhelper/postrm-apache211
-rw-r--r--debian/debhelper/prerm-apache211
6 files changed, 1126 insertions, 0 deletions
diff --git a/debian/debhelper/apache2-maintscript-helper b/debian/debhelper/apache2-maintscript-helper
new file mode 100644
index 0000000..e5b72f6
--- /dev/null
+++ b/debian/debhelper/apache2-maintscript-helper
@@ -0,0 +1,506 @@
+# apache2-maintscript-helper - Apache2 helper function for maintainer scripts
+# Copyright (C) 2012 Arno Töll <debian@toell.net>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy of
+# this software and associated documentation files (the "Software"), to deal in
+# the Software without restriction, including without limitation the rights to
+# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+# the Software, and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+
+
+#
+# VARIABLES
+#
+
+
+# global environment variables used by apache2-maintscript-helper:
+# * APACHE2_MAINTSCRIPT_DEBUG:
+# set this to any non-zero value to get debug output
+# * APACHE2_MAINTSCRIPT_HELPER_QUIET:
+# set this to any non-zero value to omit any output
+# * EXPORT_APACHE2_MAINTSCRIPT_HELPER:
+# will be defined by apache2-maintscript-helper
+# to avoid inclusion loops. Do not set this
+# variable manually
+# * APACHE2_NEED_ACTION:
+# will be defined if a function call wants to
+# override the behavior of apache2_needs_action.
+# Do not rely on this variable. It is considered
+# an implementation detail.
+# * APACHE2_MAINTSCRIPT_NAME
+# * APACHE2_MAINTSCRIPT_PACKAGE
+# * APACHE2_MAINTSCRIPT_METHOD
+# * APACHE2_MAINTSCRIPT_ARGUMENT
+# these variables contain information about the
+# maintainer script which is calling the
+# maintscript-helper. It contains arguments which
+# dpkg supplies to maintainer scripts and similar
+# information. These variables are an
+# implementation detail and not to be changed.
+#
+# You might want to set them manually only if you
+# are calling apache2-maintscript-helper from
+# some place which does not preserve the original
+# script arguments for example when calling from
+# a subfunction instead of the main function in
+# your maintainer script
+
+#
+# INITIALIZATION
+#
+
+if [ -n "${EXPORT_APACHE2_MAINTSCRIPT_HELPER:-}" ] ; then
+ return
+else
+ EXPORT_APACHE2_MAINTSCRIPT_HELPER=1
+
+ if [ -n "${APACHE2_MAINTSCRIPT_DEBUG:-}" ] ; then
+ set -x
+ elif [ -e /etc/apache2/envvars ] ; then
+ APACHE2_MAINTSCRIPT_DEBUG=$(. /etc/apache2/envvars && echo ${APACHE2_MAINTSCRIPT_DEBUG})
+ if [ -n "${APACHE2_MAINTSCRIPT_DEBUG:-}" ] ; then
+ set -x
+ fi
+ fi
+
+ APACHE2_MAINTSCRIPT_DEFER=
+ if ! dpkg-query -f '${Status}' -W apache2|egrep -q 'installed|triggers-awaited|triggers-pending'; then
+ echo "Package apache2 is not configured yet. Will defer actions by package $DPKG_MAINTSCRIPT_PACKAGE."
+ APACHE2_MAINTSCRIPT_DEFER=/var/lib/apache2/deferred_actions
+ fi
+
+ if [ -z "$1" ] ; then
+ echo "You must invoke apache2-maintscript-helper with an unmodified environment when sourcing it" >&2
+ return 1
+ fi
+
+ APACHE2_MAINTSCRIPT_NAME="$DPKG_MAINTSCRIPT_NAME"
+ [ "$APACHE2_MAINTSCRIPT_NAME" ] || APACHE2_MAINTSCRIPT_NAME="${0##*.}"
+
+ case "$APACHE2_MAINTSCRIPT_NAME" in
+ preinst|prerm|postrm|postinst)
+ # yay - recognized script
+ ;;
+ *)
+ echo "apache2-maintscript-helper invoked from an unrecognized maintainer script: exiting" >&2
+ return 1
+ ;;
+ esac
+
+ APACHE2_MAINTSCRIPT_PACKAGE="$DPKG_MAINTSCRIPT_PACKAGE"
+ if [ -z "$APACHE2_MAINTSCRIPT_PACKAGE" ]; then
+ APACHE2_MAINTSCRIPT_PACKAGE="${0##*/}"
+ APACHE2_MAINTSCRIPT_PACKAGE="${APACHE2_MAINTSCRIPT_PACKAGE%.*}"
+ fi
+
+ if [ -z "$APACHE2_MAINTSCRIPT_METHOD" ] ; then
+ APACHE2_MAINTSCRIPT_METHOD="$1"
+ fi
+
+ case "$APACHE2_MAINTSCRIPT_METHOD" in
+ install|upgrade|abort-upgrade|configure|deconfigure|abort-remove|abort-remove|abort-deconfigure|remove|failed-upgrade|purge|disappear|abort-install|triggered)
+ # yay - recognized script
+ ;;
+ *)
+ echo "apache2-maintscript-helper invoked from a modified environment. Please hint required arguments manually" >&2
+ return 1
+ ;;
+ esac
+
+
+
+ if [ -z "$APACHE2_MAINTSCRIPT_ARGUMENT" ] ; then
+ APACHE2_MAINTSCRIPT_ARGUMENT="${2:-}"
+ fi
+
+fi
+
+
+
+#
+# FUNCTIONS
+#
+
+
+#
+# Function apache2_msg
+# print out a warning to both, the syslog and a local standard output.
+# This function should generally be used to display messages related to
+# the web server in maintainer scripts.
+# Parameters:
+# priority
+# The message priority. Recognized values are the same as defined
+# by syslog(3), thus: one among debug, info, notice, warning,
+# err, crit, alert, emerg.
+# If no known priority is recognized, the priority is set to
+# "warning".
+# message
+# The message as a string. It is printed out verbatim.
+# Behavior:
+# No message is displayed if APACHE2_MAINTSCRIPT_HELPER_QUIET is defined
+# Returns:
+# this function always returns 0
+# Since: 2.4.1-3
+apache2_msg()
+{
+ local PRIORITY="$1"
+ local MSG="$2"
+ [ -z "$APACHE2_MAINTSCRIPT_HELPER_QUIET" ] && echo "$MSG" >&2
+ [ -x /usr/bin/logger ] || return 0
+ case "$PRIORITY" in
+ debug|info|notice|warning|err|crit|alert|emerg)
+ ;;
+ *)
+ PRIORITY="warning"
+ ;;
+ esac
+ local LOGGER="/usr/bin/logger -p daemon.$PRIORITY -t $APACHE2_MAINTSCRIPT_PACKAGE "
+ $LOGGER "$MSG" || return 0
+}
+
+#
+# Function apache2_needs_action
+# succeeds if the package invoking the maintscript helper
+# needs any work. This function can be used as a conditional whether a
+# certain function should be executed by means of the package state.
+# Note, calling some other functions may change the outcome of this
+# function, depending on the action required
+#Parameters:
+# none
+# Returns:
+# 0 if an older version of the maintainer script invoking the helper is
+# already installed
+# 1 otherwise
+# Since: 2.4.1-3
+apache2_needs_action()
+{
+ # Summary how the maintscript behaves:
+ # preinst:
+ # Not sure why anyone would like to call this function in preinst. Die loud.
+ # prerm remove:
+ # Basically the same as postrm. If a maintainer would like to
+ # disable his module before removing his stuff, be it.
+ # However, we have nothing useful to do if we're called in any
+ # other way than "remove" in prerm.
+ # postinst configure
+ # Probably the most important invokation. When invoked in configure we:
+ # - enable the piece of configuration on fresh installs
+ # - do nothing on upgrades UNLESS the configuration was removed automatically in the past
+ # postrm remove|purge
+ # - disable the configuration, mark it as automatically disabled in remove
+ # - disable the configuration, remove any trace we have on purge
+
+ case "$APACHE2_MAINTSCRIPT_NAME" in
+ preinst)
+ apache2_msg "info" "apache2_needs_action: The maintainer helper can not be called in preinst"
+ return 1
+ ;;
+ prerm|postrm)
+ case "$APACHE2_MAINTSCRIPT_METHOD" in
+ remove|purge)
+ return 0
+ ;;
+ *)
+ return 1
+ ;;
+ esac
+ ;;
+ postinst)
+ if [ "$APACHE2_MAINTSCRIPT_METHOD" = "configure" ] ; then
+ # act on fresh installs
+ [ -z "$APACHE2_MAINTSCRIPT_ARGUMENT" ] && return 0
+ # act if someone told us
+ [ -n "$APACHE2_NEED_ACTION" ] && return 0
+ fi
+ ;;
+ esac
+
+ return 1
+}
+
+
+
+#
+# Function apache2_has_module
+# checks whether a supplied module is enabled in the current Apache server
+# configuration
+# Parameters:
+# module - the module name which should be checked. Can be a regular
+# string or a Perl compatible regular expression e.g. cgi(d|)
+# Returns:
+# 0 if the module(s) was/were found
+# 1 otherwise
+# Since: 2.4.1-1
+apache2_has_module()
+{
+ [ -x /usr/sbin/a2query ] || return 1
+ local MODULE="$1"
+ if a2query -m "$MODULE" > /dev/null ; then
+ return 0
+ fi
+
+ return 1
+}
+
+#
+# Function apache2_switch_mpm
+# switches the MPM enabled on the web server. This function switches the
+# MPM unconditionally but does careful checks to make sure the web server
+# is left back with a working MPM.
+# It checks whether the supplied MPM exists and enables it on purpose.
+# Parameters:
+# mpm - change the MPM to the supplied argument. It should be given
+# without "mpm_" prefix, e.g. "worker", "prefork", and so on.
+# Returns:
+# 0 if the MPM could be changed
+# 1 otherwise
+# Since: 2.4.1-1
+apache2_switch_mpm()
+{
+ [ -x /usr/sbin/a2query ] || return 1
+ [ -x /usr/sbin/a2dismod ] || return 1
+ [ -x /usr/sbin/a2enmod ] || return 1
+
+ local MPM="$1"
+ MPM="${MPM#mpm_}"
+
+ if [ -n "$APACHE2_MAINTSCRIPT_DEFER" ] ; then
+ echo "$APACHE2_MAINTSCRIPT_PACKAGE apache2_switch_mpm $*" >> $APACHE2_MAINTSCRIPT_DEFER
+ return 0
+ fi
+
+ if [ ! -e "/etc/apache2/mods-available/mpm_$MPM.load" ] ; then
+ apache2_msg "err" "apache2_switch_mpm: MPM $MPM not found"
+ return 1
+ fi
+
+ local a2query_ret=0
+ a2query -m "mpm_$MPM" > /dev/null 2>&1 || a2query_ret=$?
+
+ case $a2query_ret in
+ 0)
+ apache2_msg "info" "apache2_switch_mpm $MPM: No action required"
+ return 0
+ ;;
+ 32)
+ apache2_msg "info" "apache2_switch_mpm $MPM: Has been disabled manually, not changing"
+ return 1
+ ;;
+
+ esac
+
+ local CUR_MPM=$(a2query -M) || return 1
+
+ a2dismod -m -q "mpm_$CUR_MPM";
+ a2enmod -m -q "mpm_$MPM";
+ apache2_msg "info" "apache2_switch_mpm Switch to $MPM"
+
+ if ! apache2_has_module "mpm_$MPM" ; then
+ # rollback
+ a2enmod -m -q "mpm_$CUR_MPM"
+ apache2_msg "warning" "apache2_switch_mpm Switch to $MPM failed. Rolling back to $CUR_MPM"
+ return 1
+ fi
+
+
+ APACHE2_NEED_ACTION=1
+ apache2_reload restart
+ return 0
+
+}
+
+#
+# Function apache2_invoke
+# invokes an Apache 2 configuration helper to enable or disable a
+# particular piece of configuration, a site or a module. It carefully
+# checks whether the supplied configuration snippet exists and reloads the
+# web server if the site administrator desires that by calling the
+# apache2_reload function.
+# Parameters:
+# command - The command to invoke. Recognized commands are "enconf",
+# "enmod", "ensite", "disconf", "dismod", "dissite"
+# arguments
+# - A single argument (e.g. a module) which shall be
+# enabled or disabled respectively. Do not enable module
+# dependencies that way, instead use module dependencies as
+# documented in </usr/share/doc/apache2/PACKAGING>.
+# rcd-action
+# - An optional rc.d action to override the default which is to
+# reload the web server for sites and configurations but restart
+# it for modules. Recognized arguments are "restart" and "reload"
+# Returns
+# 0 if the changes could be activated
+# 1 otherwise
+# Since: 2.4.1-3
+# Changes: 2.4.2-2: Added the second, optional argument
+# 2.4.6-4: Allow apache2_invoke to disable configuration in preinst/postinst
+apache2_invoke()
+{
+ local CMD="$1"
+ local CONF="$2"
+ local RCD_ACTION="$3"
+ local invoke_rcd=0
+ local check_switch=""
+ local invoke_string=""
+
+ [ -x "/usr/sbin/a2$CMD" ] || return 1
+ [ -x "/usr/sbin/a2query" ] || return 1
+
+ if [ -n "$APACHE2_MAINTSCRIPT_DEFER" ] ; then
+ echo "$APACHE2_MAINTSCRIPT_PACKAGE apache2_invoke $*" >> "$APACHE2_MAINTSCRIPT_DEFER"
+ return 0
+ fi
+
+ case "${RCD_ACTION:-}" in
+ ""|reload|restart)
+ ;;
+ *)
+ return 1
+ ;;
+ esac
+
+ case "$CMD" in
+ *conf)
+ check_switch="-c"
+ invoke_string="configuration"
+ rcd_action="${RCD_ACTION:-reload}"
+ ;;
+ *mod)
+ check_switch="-m"
+ invoke_string="module"
+ rcd_action="${RCD_ACTION:-restart}"
+ ;;
+ *site)
+ check_switch="-s"
+ invoke_string="site"
+ rcd_action="${RCD_ACTION:-reload}"
+ ;;
+ *)
+ ;;
+ esac
+
+
+ case "$CMD" in
+ enconf|enmod|ensite)
+ local a2query_ret=0
+ a2query $check_switch "$CONF" > /dev/null 2>&1 || a2query_ret=$?
+ if [ "$a2query_ret" -eq 0 ] ; then
+ # configuration is already enabled
+ apache2_msg "info" "apache2_invoke $CONF: already enabled"
+ APACHE2_NEED_ACTION=1
+ elif [ "$a2query_ret" -eq 32 ] ; then
+ # the admin disabled the module
+ apache2_msg "info" "apache2_invoke $CONF: no action - $invoke_string was disabled by local admin"
+ return 0
+ else
+ # coming here either means:
+ # a) we have no clue about the module (e.g. for upgrades prior to maintscript-helper
+ # b) it's a fresh install
+ APACHE2_NEED_ACTION=1
+ a2$CMD -m -q "$CONF" > /dev/null 2>&1 || return 1
+ apache2_msg "info" "apache2_invoke: Enable $invoke_string $CONF"
+ fi
+ ;;
+ disconf|dismod|dissite)
+ local a2query_ret=0
+ a2query $check_switch "$CONF" > /dev/null 2>&1 || a2query_ret=$?
+ if [ "$a2query_ret" -eq 0 ] ; then
+ if [ "$APACHE2_MAINTSCRIPT_NAME" = 'postrm' ] && [ "$APACHE2_MAINTSCRIPT_METHOD" = "purge" ] ; then
+ a2$CMD -p -f -q "$CONF" || return 1
+ apache2_msg "info" "apache2_invoke $APACHE2_MAINTSCRIPT_NAME: Purging $invoke_string $CONF"
+ APACHE2_NEED_ACTION=1
+ elif [ "$APACHE2_MAINTSCRIPT_NAME" = 'postrm' ] || [ "$APACHE2_MAINTSCRIPT_NAME" = 'prerm' ] ||
+ [ "$APACHE2_MAINTSCRIPT_NAME" = 'postinst' ] || [ "$APACHE2_MAINTSCRIPT_NAME" = 'preinst' ] ; then
+ if [ "$APACHE2_MAINTSCRIPT_METHOD" = "remove" ] ; then
+ a2$CMD -m -f -q "$CONF" || return 1
+ apache2_msg "info" "apache2_invoke $APACHE2_MAINTSCRIPT_NAME: Disable $invoke_string $CONF"
+ APACHE2_NEED_ACTION=1
+ fi
+ else
+ apache2_msg "error" "apache2_invoke: $invoke_string $CONF not supported in $APACHE2_MAINTSCRIPT_NAME"
+ return 1
+ fi
+ elif [ "$a2query_ret" -eq 32 ] || [ "$a2query_ret" -eq 33 ] ; then
+ if [ "$APACHE2_MAINTSCRIPT_NAME" = 'postrm' ] && [ "$APACHE2_MAINTSCRIPT_METHOD" = "purge" ] ; then
+ apache2_msg "info" "apache2_invoke $APACHE2_MAINTSCRIPT_NAME: Purging state for $CONF"
+ # this will return RC=1
+ ( a2$CMD -p -f -q "$CONF" > /dev/null 2>&1 )
+ else
+ apache2_msg "info" "apache2_invoke $CONF $APACHE2_MAINTSCRIPT_NAME: No action required"
+ fi
+ else
+ apache2_msg "info" "apache2_invoke $CONF $APACHE2_MAINTSCRIPT_NAME: No action required"
+ fi
+ ;;
+ *)
+ return 1
+ ;;
+ esac
+
+ if [ -n "${APACHE2_NEED_ACTION:-}" ] ; then
+ apache2_reload $rcd_action
+ fi
+
+}
+
+#
+# Function apache2_reload
+# reloads the web server to activate a changed configuration. It does not
+# actually reload the web server if the current configuration fails to
+# parse.
+# Parameters:
+# action - optional, can be 'reload' (default) or 'restart'
+# Returns:
+# 0 if the changes could be activated
+# 1 otherwise
+# Since: 2.4.1-1
+apache2_reload()
+{
+ if ! apache2_needs_action ; then
+ return 0
+ fi
+ if [ -n "$APACHE2_MAINTSCRIPT_DEFER" ] ; then
+ return 0
+ fi
+
+ local action
+ case "${1:-}" in
+ ""|reload)
+ action=reload
+ ;;
+ restart)
+ action=restart
+ ;;
+ *)
+ return 1
+ ;;
+ esac
+
+ local tmpfile=$(mktemp)
+ if apache2ctl configtest > $tmpfile 2>&1; then
+ invoke-rc.d apache2 $action || true
+ else
+ apache2_msg "err" "apache2_reload: Your configuration is broken. Not ${action}ing Apache 2"
+ grep -v -e "Action 'configtest' failed." \
+ -e "The Apache error log may have more information." \
+ "$tmpfile" |
+ while read LINE ; do
+ apache2_msg "err" "apache2_reload: $LINE"
+ done
+ fi
+ rm -f "$tmpfile"
+}
+
+# vim: syntax=sh sw=8 sts=8 sr noet
diff --git a/debian/debhelper/apache2.pm b/debian/debhelper/apache2.pm
new file mode 100644
index 0000000..204e61c
--- /dev/null
+++ b/debian/debhelper/apache2.pm
@@ -0,0 +1,8 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use Debian::Debhelper::Dh_Lib;
+
+insert_after("dh_install", "dh_apache2");
+
+1;
diff --git a/debian/debhelper/dh_apache2.in b/debian/debhelper/dh_apache2.in
new file mode 100755
index 0000000..dcb5f59
--- /dev/null
+++ b/debian/debhelper/dh_apache2.in
@@ -0,0 +1,582 @@
+#! /usr/bin/perl
+
+# dh_apache2 - Apache2 configuration elper for debhelper
+# Copyright (C) 2012 Arno Töll <debian@toell.net>
+#
+# This program is licensed at your choice under the terms of the GNU General
+# Public License vserion 2+ or under the terms of the Apache Software License
+# 2.0.
+#
+# For GPL-2+:
+# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# For ASF 2.0:
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+use strict;
+use File::Find;
+use Debian::Debhelper::Dh_Lib;
+
+
+=head1 NAME
+
+dh_apache2 - register configuration snippets to the Apache web server
+
+=cut
+
+# auto-generated do not edit
+our $API = "__API__";
+our $OPENSSL = "__OPENSSL__";
+our $MODULE_DIR = "__MODULE_DIR__";
+our $SERVER_VERSION = "__SERVER_VERSION__";
+
+sub apache_api_version
+{
+ return "apache2-api-$API";
+}
+
+sub apache_api_ssl_version
+{
+ return "apache2-api-$API-$OPENSSL";
+}
+
+sub apache_depends
+{
+ # TODO XXX this should be determined from ap_mmn.h, too.
+ my $ret = apache_api_version() . ", apache2-bin ( >= 2.4.16 )";
+ if (have_apache2_ssl_dev()) {
+ $ret .= ", " . apache_api_ssl_version();
+ }
+ return $ret;
+}
+
+sub apache_version
+{
+ return ">= $SERVER_VERSION~";
+}
+
+sub apache_api_installdir
+{
+ return $MODULE_DIR;
+}
+
+sub apache_conf_installdir
+{
+ my $type = shift;
+ return "etc/apache2/${type}-available/"
+}
+
+sub have_apache2_ssl_dev
+{
+ open(my $fd, "<", "debian/control") or die "Cannot open debian/control: $!";
+ my $line;
+ my $builddeps = "";
+ while (defined ($line = <$fd>)) {
+ chomp $line;
+ if ($line =~ m{^Build-Depends:}i) {
+ $builddeps .= $line;
+ } elsif ($builddeps) {
+ if ($line =~ m{^\s}) {
+ $builddeps .= $line;
+ } else {
+ last;
+ }
+ }
+ }
+ if ($builddeps =~ m{\bapache2-ssl-dev\b}) {
+ return 1;
+ } else {
+ return;
+ }
+}
+
+=head1 SYNOPSIS
+
+B<dh_apache2> [S<I<debhelper options>>] [S<B<--conditional>>=I<expression>] [B<--error-handler=>I<function>] [B<-n>|B<--noscripts>]
+ [B<-e>|B<--noenable>] [B<-r>|B<--restart>]
+
+=head1 DESCRIPTION
+
+B<dh_apache2> is a debhelper program that is responsible for correctly installing
+Apache2 configuration snippets and setting postinst, prerm and dependencies in
+Apache2 web server modules and web applications.
+
+It supports the following configuration types
+
+=over 4
+
+=item *
+Apache2 modules
+
+=item *
+Apache2 configuration snippets for web applications
+
+=item *
+Apache2 sites
+
+=back
+
+B<dh_apache2> supports two modes: A limited auto-configuration heuristic or
+alternatively a configuration file driven approach. If a file named
+debian/package.apache2 exists, actual actions are determined by that file.
+
+=head1 OPERATION MODES
+
+B<dh_apache2> can be used in two modes: A configuration file driven approach and
+a heuristic approach. The configuration driven mode is fully documented in the
+B<FILES> section below. This mode is activated by supplying a L<debhelper(7)>
+configuration file (e.g. debian/I<package>.apache2).
+
+The alternative is a heuristic mode, in which no files are installed through
+B<dh_apache2>. Instead the helper will scan the package installation directory
+for recognized files and guess their purpose depending on their installation
+path in the file system. Use with caution.
+
+=head1 INVOCATION
+
+B<dh_apache2> is not part of debhelper and might require information available
+in the apache2-dev package. Packages making use of B<dh_apache2> should declare
+a build-dependency against the virtual B<dh-apache2> package.
+
+B<dh_apache2> supports both, called directly from a debian/rules file or as
+L<dh(1)> addon. In the former case the helper should run after L<dh_install(1)>
+or their respective counter parts in local implementations at earliest.
+Alternatively it can be used as L<dh> addon by invoking it with
+
+ %:
+ dh $@ --with apache2
+
+=head1 FILES
+
+=over 4
+
+=item debian/I<package>.apache2
+
+=item debian/apache2
+
+=back
+
+Lists files to be registered with the Apache 2 HTTP server. The file is
+interpreted as line separated list of installation stanzas, where each entry
+consists of whitespace separated values conforming to the file semantics below.
+
+=head2 FILE SEMANTICS
+
+Each line consists of a triple
+
+I<type> I<file> [I<arguments>]
+
+where the values are interpreted as follows:
+
+
+=head3 I<type>
+
+Denotes the type of file to be installed. Recognized values are B<conf>
+for Apache2 global configuration snippets, B<site> for virtual host
+configurations and B<mod> for Apache2 modules.
+
+=head3 I<file>
+
+Is interpreted as existing file name within the source package. No path
+expansion is effectuated. Just like L<dh_install(1)>, B<dh_apache2> can not
+rename files.
+
+=head3 I<arguments>
+
+Is inrerpreted as optional arguments if any, currently used by B<conf>
+stanzas only
+
+=head2 GLOBAL CONFIGURATION FILES
+
+Global configuration files (determined by the B<conf> type) must have a I<.conf>
+suffix and are installed to I</etc/apache2/conf-available>. Moreover, the
+configuration is activated in the maintainer script at installation time.
+
+Such global configuration snippets are supposed to be used by web applications.
+Such stanzas accept an optional third I<arguments> which is interpreted as
+dependency line of alternative web servers the package supports. See I<EXAMPLES>
+below.
+
+B<dh_apache2> will set dependencies in B<${misc:Recommends}> accordingly when
+this type of configuration is found. Alternatives from the optional I<argument>
+is incorporated into this dependency line.
+
+=head2 SITE CONFIGURATION FILES
+
+Site configuration files (determined by the B<site> type) must have a I<.conf>
+suffix and are installed to I</etc/apache2/sites-available>. Moreover, the
+configuration is activated in the maintainer script at installation time.
+
+Such global configuration snippets are supposed to be used by web applications
+and third party packages which install virtual host configurations. This type of
+configuration sets the same dependencies as configuration files.
+
+=head2 MODULES
+
+Modules are handled specially and are determined by the B<mod> type. Modules can
+either have a I<.conf> or I<.load> suffix. In that case the file is interpreted
+as module load file or module configuration file respectively and is nstalled to
+I</etc/apache2/mods-available>. If the file is ending with a I<.so> suffix it is
+interpreted as actual module shared object and is installed to the Apache module
+directory. Moreover, if a I<.load> file is installed the configuration is
+activated in the maintainer script at installation time.
+
+A typical module configuration has two lines, one for the I<.load> file, and one
+for the I<.so> file, albeit the latter could be installed by upstream's
+makefile, too.
+
+B<dh_apache2> will set dependencies in B<${misc:Depends}> accordingly when
+this type of configuration is found.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<--error-handler=>I<function>
+
+Call the named shell I<function> if running the maintainer script fails. The
+function should be provided in the F<prerm> and F<postinst> scripts, before the
+B<#DEBHELPER#> token.
+
+=item S<B<--conditional>>=I<function>
+
+Only execute maintainer scripts if the named shell I<function> evaluates to a
+true value at installation time. This is useful to web applications which want
+to install Apache configuration files depending on a user input, for example if
+they interface to the user through L<debconf(1)>.
+
+The defaults is to always execute the scripts. The named function should be
+provided in the F<prerm>, F<postrm> and F<postinst> scripts, before the
+B<#DEBHELPER#> token.
+
+=item S<B<--restart>> S<B<-r>>
+
+In maintainer scripts, do not try to reload the web server, but restart it.
+Otherwise the default action is used, which means global configuration and
+sites make the web server to be reloaded on success, modules are restarted.
+
+=item B<-e>, B<--noenable>
+
+Install maintainer scripts accordingly, but do not enable the scripts or
+configuration by default.
+
+=item B<-n>, B<--noscripts>
+
+Do not modify F<postinst>/F<postrm>/F<prerm> maintainer scripts.
+
+
+=back
+
+=head1 NOTES
+
+Note that this command is not idempotent. L<dh_prep(1)> should be called
+between invocations of this command. Otherwise, it may cause multiple
+instances of the same text to be added to maintainer scripts.
+
+=head1 EXAMPLES
+
+The examples below lists valid entries for a debian/I<package>.apache2 file. For
+example, the two lines below install a fictional I<mod_foo> Apache module along
+a Debian specific I<.load> file:
+
+ mod src/foo/mod_foo.so
+ mod debian/foo.load
+
+The example below installs a fictional web application called phpmyfoo supplied
+in a package which also supports Lighttpd and nginx:
+
+ conf debian/phpmyfoo.conf lighttpd (>= 1.4.30) | nginx-full
+
+Or, the same example again this time without support for other web servers:
+
+ conf debian/phpmyfoo.conf
+
+As a final example, install a module called I<mod_foo> along with a site
+configuration for a fictional site configuration for the site I<example.com>:
+
+ mod src/foo/mod_foo.so
+ mod debian/foo.load
+ mod debian/foo.conf
+ site debian/example_com.conf
+
+=head1 SEE ALSO
+
+L<apache2ctl>(8), L<a2query>(8), L<debhelper>(7), L<dh>(1)
+
+=head1 AUTHOR
+
+This manual and L<dh_apache2> was written by Arno Toell <debian@toell.net>.
+
+=cut
+
+
+##
+## main code starts here
+##
+
+init(options => {
+ "conditional=s" => \$dh{CONDITIONAL},
+ "r|restart" => \$dh{RESTART},
+ "e|noenable" => \$dh{NOENABLE},
+});
+
+if (!$dh{CONDITIONAL})
+{
+ $dh{CONDITIONAL} = 'true';
+}
+elsif ($dh{CONDITIONAL} !~ /^\w+$/) {
+ die "The conditional function name must only contain ASCII letters, numbers, and underscores\n";
+}
+
+if ($dh{RESTART})
+{
+ $dh{RESTART} = 'restart';
+}
+else
+{
+ $dh{RESTART} = '';
+}
+
+foreach my $package ((@{$dh{DOPACKAGES}}))
+{
+ my %PACKAGE_TYPE = (
+ has_a_module => [],
+ has_a_conf_file => [],
+ has_a_site_conf => [],
+ dependency_line => "",
+ handler => $dh{ERROR_HANDLER},
+ conditional => $dh{CONDITIONAL}
+ );
+
+ my $file = pkgfile($package, "apache2");
+ my $tmp = tmpdir($package);
+
+ my @files_to_register = filedoublearray($file, ".") if $file;
+ foreach my $line (@files_to_register)
+ {
+ my $type = lc(shift @{$line}) if $line->[0];
+ my $source = shift @{$line} if $line->[0];
+ my @arguments = map {"$_ "} @{$line};
+
+ $type .= "s" unless $type eq "conf";
+ my $installdir = $tmp . "/" . apache_conf_installdir($type);
+
+ #verbose_print("$type -- $source -- @arguments\n\n");
+
+ if ($type eq "mods" or $type eq "sites" or $type eq "conf")
+ {
+ my $basesource = basename($source);
+
+ if ($type eq "mods")
+ {
+ if ($basesource =~ m/\.load$/)
+ {
+ my $enablename = $basesource;
+ $enablename =~ s/\.load$//;
+ push @{$PACKAGE_TYPE{'has_a_module'}}, $enablename;
+ verbose_print("Installing module configuration $enablename into $installdir\n");
+ }
+ elsif ($basesource =~ m/\.so$/)
+ {
+ my $modinstalldir = $tmp . "/" . apache_api_installdir();
+ verbose_print("Installing module binary $source into $modinstalldir\n");
+ if (! -d $modinstalldir)
+ {
+ complex_doit("mkdir","-p", $modinstalldir);
+ complex_doit("chmod","755","$modinstalldir");
+ }
+ complex_doit("cp", $source, $modinstalldir);
+ next;
+ }
+
+ error("module: \"$basesource\" needs .conf, .so or .load suffix") if $basesource !~ m/\.(conf|load|so)/;
+ }
+ elsif ($type eq "sites")
+ {
+ push @{$PACKAGE_TYPE{'has_a_site_conf'}}, $basesource;
+ verbose_print("Installing site configuration $basesource into $installdir\n");
+ }
+ elsif($type eq "conf")
+ {
+
+ if ($#arguments >= 0)
+ {
+ $PACKAGE_TYPE{'dependency_line'} .= " | " . join("", @arguments);
+ }
+
+ if ($basesource =~ m/\.conf/)
+ {
+ my $enablename = $basesource;
+ $enablename =~ s/\.conf$//;
+ push
+ @{$PACKAGE_TYPE{'has_a_conf_file'}}, $enablename;
+ verbose_print("Installing global configuration $enablename into $installdir\n");
+ }
+ error("configuration file: \"$basesource\" needs .conf suffix") if $basesource !~ m/\.conf/;
+ }
+
+ if (! -d $installdir)
+ {
+ complex_doit("mkdir","-p",$installdir);
+ complex_doit("chmod","755","$installdir");
+ }
+ complex_doit("cp",$source,$installdir);
+ complex_doit("chmod","644","$installdir/$basesource");
+
+ }
+ else
+ {
+ error("Unknown parameter: $type\n");
+ }
+
+ }
+
+
+ if (! $file)
+ {
+ # do black magic only if there is no .apache2 configuration file
+ find({ no_chdir => 1,
+ wanted => sub
+ {
+ my ($dir, $file) = (dirname($File::Find::name), basename($File::Find::name));
+ # remove extension
+ my $conf_name = $file;
+ $conf_name =~ s/\.[^.]+$//;
+
+ if ($dir =~ m#etc/apache2/mods-available# and $file =~ m#.(load|conf)$#)
+ {
+ verbose_print("package $package appears to be a web server module\n");
+ push @{$PACKAGE_TYPE{'has_a_module'}}, $conf_name if $file =~ m/\.load/;
+ }
+ if ($dir =~ m#etc/apache2/sites-available# and $file =~ m#.conf$#)
+ {
+ verbose_print("package $package appears to contain a virtual host configuration\n");
+ push @{$PACKAGE_TYPE{'has_a_site_conf'}}, $conf_name;
+ }
+ if ($dir =~ m#etc/apache2/conf-available# and $file =~ m#.conf$#)
+ {
+ verbose_print("package $package appears to contain a global configuration file \n");
+ push @{$PACKAGE_TYPE{'has_a_conf_file'}}, $conf_name;
+ }
+
+
+
+ }}, tmpdir($package));
+ }
+
+
+ my @postinst_autoscripts;
+
+ if ($#{$PACKAGE_TYPE{'has_a_module'}} >= 0)
+ {
+ if ($package !~ m/libapache2-mod-\w+?/)
+ {
+ warning("Package $package appears to be an Apache module. It should comply to the package naming scheme libapache2-mod-<modulename>\n");
+ }
+ addsubstvar($package, "misc:Depends", apache_depends());
+
+ my $modules = "";
+ foreach my $module (@{$PACKAGE_TYPE{'has_a_module'}})
+ {
+ $modules .= "$module ";
+ }
+
+ push @postinst_autoscripts, ["enmod", $modules];
+ }
+
+ if ($#{$PACKAGE_TYPE{'has_a_conf_file'}} >= 0 or $#{$PACKAGE_TYPE{'has_a_site_conf'}} >= 0)
+ {
+ $PACKAGE_TYPE{'dependency_line'} .= "| httpd";
+ addsubstvar($package, "misc:Recommends", "apache2 ( >= 2.4.6-4~ ) " . $PACKAGE_TYPE{'dependency_line'} );
+
+ my $confs = "";
+ my $sites = "";
+
+ foreach my $conf (@{$PACKAGE_TYPE{'has_a_conf_file'}})
+ {
+ $confs .= "$conf ";
+ }
+
+ foreach my $site (@{$PACKAGE_TYPE{'has_a_site_conf'}})
+ {
+ $sites .= "$site ";
+ }
+
+ if ($confs)
+ {
+ push @postinst_autoscripts, ["enconf", $confs];
+ }
+ if ($sites)
+ {
+ push @postinst_autoscripts, ["ensite", $sites];
+ }
+
+ }
+
+ if (! $dh{NOSCRIPTS})
+ {
+ foreach my $ref (@postinst_autoscripts)
+ {
+ for my $script_type (qw/postinst prerm postrm/)
+ {
+ if ($script_type eq "postinst" && $dh{NOENABLE})
+ {
+ next
+ }
+
+ my %replacements = (
+ HELPER => $ref->[0],
+ NAMES => $ref->[1],
+ ERROR_HANDLER => $PACKAGE_TYPE{handler},
+ CONDITIONAL_VARIABLE => $PACKAGE_TYPE{conditional},
+ ACTION => $dh{RESTART},
+ );
+
+ if ($script_type eq "prerm" || $script_type eq "postrm")
+ {
+ $replacements{'HELPER'} =~ s/en/dis/;
+ }
+
+ my $sed_command = "";
+ foreach my $key (sort keys %replacements)
+ {
+ my $val = $replacements{$key};
+ # Use a control char as separator for sed, to
+ # reduce escaping issues. Everything else is
+ # passed verbatim, i.e. it must not contain any
+ # shell or sed special characters.
+ my $sep = "\x17";
+ $sed_command .= "s" . $sep . "#$key#" .
+ $sep . $val .
+ $sep . "g; ";
+ }
+
+ autoscript($package, "$script_type", "$script_type-apache2", $sed_command);
+ }
+ }
+ }
+}
+
+# vim: syntax=perl sw=8 sts=8 sr noet
diff --git a/debian/debhelper/postinst-apache2 b/debian/debhelper/postinst-apache2
new file mode 100644
index 0000000..a944514
--- /dev/null
+++ b/debian/debhelper/postinst-apache2
@@ -0,0 +1,8 @@
+if #CONDITIONAL_VARIABLE#; then
+ if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
+ . /usr/share/apache2/apache2-maintscript-helper
+ for conf in #NAMES# ; do
+ apache2_invoke #HELPER# $conf #ACTION# || #ERROR_HANDLER#
+ done
+ fi
+fi
diff --git a/debian/debhelper/postrm-apache2 b/debian/debhelper/postrm-apache2
new file mode 100644
index 0000000..89ee460
--- /dev/null
+++ b/debian/debhelper/postrm-apache2
@@ -0,0 +1,11 @@
+if [ "$1" = "purge" ] ; then
+ if #CONDITIONAL_VARIABLE#; then
+ if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
+ . /usr/share/apache2/apache2-maintscript-helper
+
+ for conf in #NAMES# ; do
+ apache2_invoke #HELPER# $conf #ACTION# || #ERROR_HANDLER#
+ done
+ fi
+ fi
+fi
diff --git a/debian/debhelper/prerm-apache2 b/debian/debhelper/prerm-apache2
new file mode 100644
index 0000000..d71d36b
--- /dev/null
+++ b/debian/debhelper/prerm-apache2
@@ -0,0 +1,11 @@
+if [ "$1" = "remove" ] || [ "$1" = "deconfigure" ] ; then
+ if #CONDITIONAL_VARIABLE#; then
+ if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
+ . /usr/share/apache2/apache2-maintscript-helper
+
+ for conf in #NAMES# ; do
+ apache2_invoke #HELPER# $conf #ACTION# || #ERROR_HANDLER#
+ done
+ fi
+ fi
+fi