[Pkg-apache-commits] [SCM] Debian packaging for apache2 (Apache HTTPD 2.x) branch, next, updated. 5dae324701fd5e3a860680f09a1b47b01c7df8e9

Arno Töll debian at toell.net
Tue Mar 6 20:34:52 UTC 2012


The following commit has been merged in the next branch:
commit 5dae324701fd5e3a860680f09a1b47b01c7df8e9
Author: Arno Töll <debian at toell.net>
Date:   Tue Mar 6 21:29:56 2012 +0100

    Extend a2query provide maintscript-helper
    
    * Parse meta variables of a2query in debian/rules, generate file from a2query.in
    * Remove stubs in dh_apache2 to call a2query instead
    * Add a dh-apache2 package for now
    * Provide an apache2-maintscript-helper which can be called from maintainer
      scripts, change postinst logic in dh_apache2 to make use of it
    * Determine the Apache API version at build time for debian/control
    * Adapt debian/rules to parse *.in files

diff --git a/debian/a2query b/debian/a2query.in
similarity index 96%
rename from debian/a2query
rename to debian/a2query.in
index 1ff2ae4..19786f9 100755
--- a/debian/a2query
+++ b/debian/a2query.in
@@ -1,12 +1,13 @@
 #! /usr/bin/perl
 
+use feature "switch";
 use strict;
 use Getopt::Std;
 
 our $APACHE2 = "apache2ctl";
-our $API = "20111203";
-our $MODULE_DIR = "/usr/lib/apache2/modules/";
-our $SERVER_VERSION = "2.4.1";
+our $API = "__API__";
+our $MODULE_DIR = "__MODULE_DIR__";
+our $SERVER_VERSION = "__SERVER_VERSION__";
 our $MPM = "invalid";
 our $CONFIG_DIR = "/etc/apache2";
 our @MODULES = ();
@@ -107,6 +108,7 @@ sub load_sites
 	closedir(DIR);
 }
 
+
 load_defaults();
 load_modules();
 
diff --git a/debian/apache2-dev.install b/debian/apache2-dev.install
index 785dd5b..f5d2707 100644
--- a/debian/apache2-dev.install
+++ b/debian/apache2-dev.install
@@ -1,7 +1,3 @@
 /usr/include/apache2
 /usr/share/apache2/build
 /usr/bin/apxs
-debian/debhelper/dh_apache2		/usr/bin
-debian/debhelper/apache2.pm		/usr/share/perl5/Debian/Debhelper/Sequence/
-debian/debhelper/postinst-apache2	/usr/share/debhelper/autoscripts/
-debian/debhelper/postrm-apache2		/usr/share/debhelper/autoscripts/
diff --git a/debian/apache2.install b/debian/apache2.install
index 7696671..4c391fb 100644
--- a/debian/apache2.install
+++ b/debian/apache2.install
@@ -1,5 +1,6 @@
-debian/bash_completion/apache2	/etc/bash_completion.d/
-debian/config-dir/*		/etc/apache2
-debian/a2enmod			/usr/sbin
-debian/apache2ctl		/usr/sbin
-debian/a2query			/usr/sbin
+debian/bash_completion/apache2			/etc/bash_completion.d/
+debian/config-dir/*				/etc/apache2
+debian/a2enmod					/usr/sbin
+debian/apache2ctl				/usr/sbin
+debian/a2query					/usr/sbin
+debian/debhelper/apache2-maintscript-helper	/usr/share/apache2/
diff --git a/debian/clean b/debian/clean
index 2369f33..c828586 100644
--- a/debian/clean
+++ b/debian/clean
@@ -10,5 +10,6 @@ debian/apache2-suexec-pristine.prerm
 debian/apache2-suexec-pristine.links
 debian/apache2-suexec-pristine.dirs
 debian/apache2-suexec-pristine.lintian-overrides
+debian/a2query
 support/suexec-custom.c
 config.nice
diff --git a/debian/control b/debian/control
index fb9935d..5b912c3 100644
--- a/debian/control
+++ b/debian/control
@@ -48,7 +48,7 @@ Package: apache2-bin
 Architecture: any
 Depends: ${shlibs:Depends}, ${misc:Depends}
 # MODULE_MAGIC_NUMBER_MAJOR from apache2/include/ap_mmn.h
-Provides: apache2-api-20120211
+Provides: ${apache2:API}
 Suggests: www-browser, apache2-doc, apache2-suexec-pristine | apache2-suexec-custom
 Replaces: apache2.2-bin (<< 2.3~), apache2.2-common (<< 2.3~),
 Breaks: apache2.2-bin (<< 2.3~), apache2.2-common (<< 2.3~),
@@ -159,7 +159,8 @@ Description: Apache HTTP Server (on-site documentation)
 
 Package: apache2-dev
 Architecture: any
-Depends: ${misc:Depends}, apache2 (= ${binary:Version}), openssl, libaprutil1-dev
+Depends: ${misc:Depends}, apache2 (= ${binary:Version}), openssl,
+ libaprutil1-dev, dh-apache2
 Priority: extra
 Provides: apache2-prefork-dev, apache2-threaded-dev
 Replaces: apache2-prefork-dev, apache2-threaded-dev
@@ -186,3 +187,16 @@ Description: Apache debugging symbols
  This package includes the debugging symbols. It can be used to debug
  crashing server instances and modules.  See
  /usr/share/doc/apache2/README.backtrace for more information.
+
+Package: dh-apache2
+Section: devel
+Priority: optional
+Architecture: all
+Depends: debhelper (>= 7.0.50~), ${misc:Depends}
+Description: Apache debhelper utilities
+ The apache debhelper provides dh_apache2 and dh sequence addons useful to
+ install various Debian Apache2 extensions. It supports
+ - Apache 2 module configurations and shared objects
+ - Site configuration files
+ - Global configuration files
+
diff --git a/debian/debhelper/apache2-maintscript-helper b/debian/debhelper/apache2-maintscript-helper
new file mode 100644
index 0000000..bdf491a
--- /dev/null
+++ b/debian/debhelper/apache2-maintscript-helper
@@ -0,0 +1,102 @@
+EXPORT_APACHE2_MAINTSCRIPT_HELPER=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
+}
+
+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=$(echo "$MPM" | sed -e 's/^mpm_//')
+
+	if [ ! -e "/etc/apache2/mods-available/mpm_$MPM.load" ] ; then
+		return 1
+	fi
+
+	CUR_MPM=$(a2query -M) || return 1
+
+	if [ $CUR_MPM != $MPM ] ; then
+		a2dismod -q "mpm_$CUR_MPM";
+		a2enmod -q "mpm_$MPM";
+	fi
+
+	if ! apache2_has_module "mpm_$MPM" ; then
+		# rollback
+		a2enmod -q "mpm_$CUR_MPM"
+		return 1
+	fi
+
+}
+
+apache2_invoke()
+{
+	local CMD=$1
+	shift
+	local invoke_rcd=0
+	local check_switch=""
+
+	[ -x "/usr/sbin/a2$CMD" ] || return 1
+	[ -x "/usr/sbin/a2query" ] || return 1
+
+	case "$CMD" in
+		*conf)
+			check_switch="-c"
+			;;
+		*mod)
+			check_switch="-m"
+			;;
+		*site)
+			check_switch="-s"
+			;;
+		*)
+			;;
+	esac
+
+	for CONF in $@ ; do
+		case "$CMD" in
+			enconf|enmod|ensite)
+				if a2query $check_switch $CONF > /dev/null 2>&1 ; then
+					continue
+				fi
+				invoke_rcd=1
+				a2$CMD -q "$CONF" || return 1
+				;;
+			disconf|dismod|dissite)
+				if ! a2query $check_switch $CONF > /dev/null 2>&1 ; then
+					continue
+				fi
+				invoke_rcd=1
+				a2$CMD -q "$CONF" || return 1
+				;;
+			*)
+				return 1
+				;;
+		esac
+	done
+
+	if [ $invoke_rcd -eq 1 ] ; then
+		apache2_reload
+	fi
+
+}
+
+
+apache2_reload()
+{
+	if apache2ctl configtest 2>/dev/null; then
+		invoke-rc.d apache2 force-reload || true
+	else
+		echo "Your configuration is broken. Not restarting Apache 2."
+	fi
+}
diff --git a/debian/debhelper/dh_apache2 b/debian/debhelper/dh_apache2
index 9285032..c3c8458 100755
--- a/debian/debhelper/dh_apache2
+++ b/debian/debhelper/dh_apache2
@@ -49,27 +49,47 @@ dh_apache2 - register configuration snippets to the Apache web server
 
 sub apache_api_version
 {
-	# TODO: replace me
-	return "apache2-api-20111203";
+	if (! -x "/usr/sbin/a2query")
+	{
+		error("package appears to be an Apache module, however there is	no a2query executable available. Missing apache2-dev build dependency?");
+	}
+	my $api = `a2query -a`;
+	chomp($api);
+	return "apache2-api-$api";
 }
 
 
 sub apache_version
 {
-	# TODO: replace me
-	return ">= 2.2~";
+	# Use a2query when available. However, some web application don't need a
+	# build-dependency against apache2 (or even apache2-dev). Return
+	# something sensible then as fallback
+	if (-x "/usr/sbin/a2query")
+	{
+		my $version = `a2query -v`;
+		chomp($version);
+		return ">= $version~";
+	}
+	else
+	{
+		return ">= 2.3~";
+	}
 }
 
 sub apache_api_installdir
 {
-	# TODO: replace me
-	return "/usr/lib/apache2/modules/";
+	if (! -x "/usr/sbin/a2query")
+	{
+		error("package appears to be an Apache module, however there is	no a2query executable available. Missing apache2-dev build dependency?");
+	}
+	my $md = `a2query -d`;
+	chomp($md);
+	return "$md";
 }
 
 sub apache_conf_installdir
 {
 	my $type = shift;
-	# TODO: replace me
 	return "etc/apache2/${type}-available/"
 }
 
@@ -426,7 +446,7 @@ foreach my $package (getpackages())
 			$modules .= "$module ";
 		}
 
-		push @postinst_autoscripts, ["a2enmod", $modules];
+		push @postinst_autoscripts, ["enmod", $modules];
 	}
 
 	if ($#{$PACKAGE_TYPE{'has_a_conf_file'}} >= 0 or $#{$PACKAGE_TYPE{'has_a_site_conf'}} >= 0)
@@ -449,11 +469,11 @@ foreach my $package (getpackages())
 
 		if ($confs)
 		{
-			push @postinst_autoscripts, ["a2enconf", $confs];
+			push @postinst_autoscripts, ["enconf", $confs];
 		}
 		if ($sites)
 		{
-			push @postinst_autoscripts, ["a2ensite", $sites];
+			push @postinst_autoscripts, ["ensite", $sites];
 		}
 
 	}
@@ -463,7 +483,7 @@ foreach my $package (getpackages())
 		foreach my $ref (@postinst_autoscripts)
 		{
 			autoscript($package, "postinst", "postinst-apache2", "s/#HELPER#/$ref->[0]/; s/#NAMES#/$ref->[1]/; s/#ERROR_HANDLER#/$PACKAGE_TYPE{'handler'}/; s/#CONDITIONAL_VARIABLE#/$PACKAGE_TYPE{'conditional'}/;");
-			$ref->[0] =~ s/a2en/a2dis/;
+			$ref->[0] =~ s/en/dis/;
 			autoscript($package, "postrm", "postrm-apache2", "s/#HELPER#/$ref->[0]/; s/#NAMES#/$ref->[1]/; s/#ERROR_HANDLER#/$PACKAGE_TYPE{'handler'}/; s/#CONDITIONAL_VARIABLE#/$PACKAGE_TYPE{'conditional'}/;");
 		}
 	}
diff --git a/debian/debhelper/postinst-apache2 b/debian/debhelper/postinst-apache2
old mode 100755
new mode 100644
index 41cf1b5..24a7a85
--- a/debian/debhelper/postinst-apache2
+++ b/debian/debhelper/postinst-apache2
@@ -1,12 +1,8 @@
 if [ "$1" = "configure" ] && #CONDITIONAL_VARIABLE#; then
-	if [ -x "/usr/sbin/#HELPER#" ] ; then
-		for S in #NAMES# ; do
-			/usr/sbin/#HELPER# -q $S || #ERROR_HANDLER#
-		done
-
-		if [ -x "/etc/init.d/apache2" ]; then
- 		      invoke-rc.d apache2 restart || #ERROR_HANDLER#
+	if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
+		if [ -z $EXPORT_APACHE2_MAINTSCRIPT_HELPER ] ; then
+			. /usr/share/apache2/apache2-maintscript-helper
 		fi
-
+		apache2_invoke #HELPER# #NAMES# || #ERROR_HANDLER#
 	fi
 fi
diff --git a/debian/debhelper/postrm-apache2 b/debian/debhelper/postrm-apache2
old mode 100755
new mode 100644
index 7e9fbaa..207ba88
--- a/debian/debhelper/postrm-apache2
+++ b/debian/debhelper/postrm-apache2
@@ -1,12 +1,8 @@
-if [ "$1" = "purge" ] && #CONDITIONAL_VARIABLE# ; then
-	if [ -x "/usr/sbin/#HELPER#" ] ; then
-		for S in #NAMES# ; do
-			/usr/sbin/#HELPER# -q $S || #ERROR_HANDLER#
-		done
-
-		if [ -x "/etc/init.d/apache2" ]; then
- 		      invoke-rc.d apache2 restart || #ERROR_HANDLER#
+if [ "$1" = "purge" ] && #CONDITIONAL_VARIABLE#; then
+	if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
+		if [ -z $EXPORT_APACHE2_MAINTSCRIPT_HELPER ] ; then
+			. /usr/share/apache2/apache2-maintscript-helper
 		fi
-
+		apache2_invoke #HELPER# #NAMES# || #ERROR_HANDLER#
 	fi
 fi
diff --git a/debian/apache2-dev.install b/debian/dh-apache2.install
similarity index 80%
copy from debian/apache2-dev.install
copy to debian/dh-apache2.install
index 785dd5b..89a0a4a 100644
--- a/debian/apache2-dev.install
+++ b/debian/dh-apache2.install
@@ -1,6 +1,3 @@
-/usr/include/apache2
-/usr/share/apache2/build
-/usr/bin/apxs
 debian/debhelper/dh_apache2		/usr/bin
 debian/debhelper/apache2.pm		/usr/share/perl5/Debian/Debhelper/Sequence/
 debian/debhelper/postinst-apache2	/usr/share/debhelper/autoscripts/
diff --git a/debian/rules b/debian/rules
index fcad191..c4b5653 100755
--- a/debian/rules
+++ b/debian/rules
@@ -5,8 +5,9 @@
 # Uncomment this to turn on verbose mode.
 export DH_VERBOSE=1
 
-LSB_RELEASE := $(shell lsb_release -i -s)
-
+SERVER_VERSION := $(shell dpkg-parsechangelog | perl -ne 'print $$1 if m/Version:\s*([\d\.]+)/')
+MODULE_DIR := /usr/lib/apache2/modules/
+API = $(shell perl -ne 'print $$1 if m/define\s+MODULE_MAGIC_NUMBER_MAJOR\s+?(.*)$$/' < include/ap_mmn.h)
 AP2_CFLAGS = -pipe $(shell dpkg-buildflags --get CFLAGS)
 AP2_LDFLAGS = -Wl,--as-needed $(shell dpkg-buildflags --get LDFLAGS)
 AP2_CPPFLAGS = -DPLATFORM='\"$(LSB_RELEASE)\"' $(shell dpkg-buildflags --get CPPFLAGS)
@@ -29,6 +30,11 @@ clean-config-vars:
 	printf "EXTRA_CFLAGS = \n" >> tmp_config_vars.mk ; \
 	mv tmp_config_vars.mk config_vars.mk ) ;
 
+prepare-a2query:
+	sed 's#__SERVER_VERSION__#$(SERVER_VERSION)#; s#__MODULE_DIR__#$(MODULE_DIR)#; s#__API__#$(API)#;' debian/a2query.in > debian/a2query ; \
+	(grep -s -v apache2:API debian/apache2-bin.substvars; echo apache2:API=apache2-api-$(API)) > debian/apache2-bin.substvars.new ; \
+	mv debian/apache2-bin.substvars.new debian/apache2-bin.substvars
+
 suexec-maintainer-scripts:
 	set -e ; \
 	for type in custom pristine ; do \
@@ -59,7 +65,7 @@ override_dh_auto_configure: prepare-custom-suexec suexec-maintainer-scripts
 		CFLAGS="$(AP2_CFLAGS)" CPPFLAGS="$(AP2_CPPFLAGS)" LDFLAGS="$(AP2_LDFLAGS)" \
 		$(AP2_EXTRAFLAGS)
 
-override_dh_install: clean-config-vars
+override_dh_install: clean-config-vars prepare-a2query
 	dh_install --list-missing
 
 override_dh_fixperms:
@@ -103,4 +109,4 @@ override_dh_auto_install:
 
 
 
-.PHONY: prepare-custom-suexec suexec-maintainer-scripts clean-config-vars
+.PHONY: prepare-custom-suexec suexec-maintainer-scripts clean-config-vars prepare-a2query

-- 
Debian packaging for apache2 (Apache HTTPD 2.x)



More information about the Pkg-apache-commits mailing list