summaryrefslogtreecommitdiff
path: root/debian
diff options
context:
space:
mode:
authorGeorgios M. Zarkadas <gz@member.fsf.org>2012-05-25 04:18:52 +0300
committerGeorgios M. Zarkadas <gz@member.fsf.org>2012-06-12 20:18:52 +0300
commit6bfdd7e7063fc2e35009a5905a5454d164ff1b3a (patch)
treeb6807b55709e5c56e2b217184f44ebe9a12d9550 /debian
parentf3ec6f938b050f72ddc2bf29116cc53682e4bd1a (diff)
Change maintainer scripts to support multiple web servers and versions of.
A side effect of the above is the spinoff of a reausable by other packages maintainer scripts library.
Diffstat (limited to 'debian')
-rw-r--r--debian/dirs7
-rwxr-xr-xdebian/postinst233
-rwxr-xr-xdebian/prerm124
-rw-r--r--debian/scripts/files.sh139
-rw-r--r--debian/scripts/httpd.sh263
-rw-r--r--debian/scripts/info.sh84
6 files changed, 780 insertions, 70 deletions
diff --git a/debian/dirs b/debian/dirs
index 085a044..66e7552 100644
--- a/debian/dirs
+++ b/debian/dirs
@@ -1,4 +1,7 @@
+usr/share/doc/HTML
var/lib/dhelp
var/lib/dhelp/tmp
-var/www/doc
-etc/apt/apt.conf.d
+/etc/apt/apt.conf.d
+/etc/apache2/conf.d
+/etc/apache2/conf-available
+/etc/lighttpd/conf-available
diff --git a/debian/postinst b/debian/postinst
index 758f432..e510981 100755
--- a/debian/postinst
+++ b/debian/postinst
@@ -1,6 +1,8 @@
-#!/bin/sh -e
+#!/bin/sh
#
-# Copyright 2001,2002 by Stefan Hornburg (Racke) <racke@linuxia.de>
+# Copyright (C) 2001,2002 Stefan Hornburg (Racke) <racke@linuxia.de>
+# Copyright (C) 2007 Esteban Manchado Velázquez <zoso@debian.org>
+# Copyright (C) 2011,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
@@ -17,69 +19,188 @@
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA.
-# create /var/lib/dhelp if necessary
-if [ ! -d /var/lib/dhelp ]; then
- mkdir /var/lib/dhelp
-fi
+set -e
-# remove /usr/doc/HTML2 if upgrading from old dhelp package
-if [ "$1" = configure -a -d /usr/doc/HTML2 ]; then
- rm -rf /usr/doc/HTML2
-fi
-
-# remove old /var/lib/dhelp/swish++.index (versions older than 0.6)
-rm -f /var/lib/dhelp/swish++.index
+#DEBHELPER#
-# hack to be able to tell if the package is configured, so 3rd party packages
-# that call dhelp don't barf (from scrollkeeper package)
-touch /var/lib/dhelp/configured
+#### Globals ####
DHELP_INDEXER=/usr/share/dhelp/scripts/index-deferred
DHELP_APTHOOK=/etc/apt/apt.conf.d/35dhelp
+DHELP_POSTCMD='Dpkg::Post-Invoke {
+ "if test -x '${DHELP_INDEXER}'; then '${DHELP_INDEXER}'; fi";
+};'
+DHELP_CONFDIR=/usr/share/dhelp/config
+DHELP_OKINDEX="false"
+
+#### Import Library ####
+
+for DHELP_LIBFILE in /usr/share/dhelp/maint-scripts/*.sh; do
+ if [ -f ${DHELP_LIBFILE} ]; then
+ . ${DHELP_LIBFILE}
+ else
+ >&2 echo "Dhelp error: file ${DHELP_LIBFILE} was not found."
+ >&2 echo "Please file a bug report at bugs.debian.org" \
+ "against the dhelp package."
+ fi
+done
+
+#### Functions ####
+
+# cleanup artifacts of previous versions
+#
+do_upgrade_cleanup_actions ()
+{
+ # remove /usr/doc/HTML, /usr/doc/HTML2 and /usr/doc/dhelp
+ # if upgrading from old dhelp package
+
+ if [ -h /usr/doc/HTML ]; then
+ rm --force /usr/doc/HTML
+ elif [ -d /usr/doc/HTML ]; then
+ rm --force --recursive /usr/doc/HTML
+ fi
+
+ if [ -d /usr/doc/HTML2 ]; then
+ rm --force --recursive /usr/doc/HTML2
+ fi
+
+ if [ -h /usr/doc/dhelp ]; then
+ rm --force /usr/doc/dhelp
+ fi
+
+ # remove old /var/lib/dhelp/swish++.index (versions older than 0.6)
+
+ if [ ! -d /var/lib/dhelp/swish++.index ]; then
+ rm --force /var/lib/dhelp/swish++.index
+ fi
+}
# create and register with ucf our dpkg post-invoke hook
+#
+register_dpkg_postinvoke_hook ()
+{
+ local dhelp_tmp_apthook=$(mktemp)
+
+ chmod 644 ${dhelp_tmp_apthook}
+ echo "${DHELP_POSTCMD}" > ${dhelp_tmp_apthook}
+
+ mv_ucfregister_file dhelp ${dhelp_tmp_apthook} ${DHELP_APTHOOK}
+}
-DHELP_POSTCMD="\"if test -x ${DHELP_INDEXER}; then ${DHELP_INDEXER}; fi\""
-DHELP_TMP_APTHOOK=`mktemp 2>/dev/null`
-if [ $? -ne 0 ]; then
- >&2 echo "Error: unable to create temporary file"
- exit 1
-fi
-if ! chmod 644 ${DHELP_TMP_APTHOOK}; then
- >&2 echo "Error: unable to change mode of temporary file"
- exit 2
-fi
-echo "Dpkg::Post-Invoke { ${DHELP_POSTCMD}; };" > ${DHELP_TMP_APTHOOK}
-
-ucf --debconf-ok --three-way ${DHELP_TMP_APTHOOK} ${DHELP_APTHOOK}
-rm -f ${DHELP_TMP_APTHOOK}
-ucfr dhelp ${DHELP_APTHOOK}
-
-# create /var/www/doc if necessary
-if [ ! -d /var/www/doc ]; then
- mkdir /var/www/doc
-fi
-
-# 'dhelp_parse -r', among other actions, produces the pending list.
-echo -n "Building HTML tree..."
-dhelp_parse -r
-echo " done."
-
-# symlink /usr/share/doc/{dhelp,HTML} from /var/www/doc
-ln -s /usr/share/doc/dhelp /var/www/doc/dhelp
-ln -s /usr/share/doc/HTML /var/www/doc/HTML
-
-# Thus, if index file does not exist, it suffices to do incremental indexing.
-if [ ! -f /var/lib/dhelp/documents.index ]; then
- echo "Reindexing documentation in the background"
- if [ -x ${DHELP_INDEXER} ]; then
- ${DHELP_INDEXER}
+# build the set of html files inside /usr/share/doc/HTML
+#
+build_document_index ()
+{
+ local ret=0
+
+ # 'dhelp_parse -r', among other actions, produces the pending list.
+ echo -n "Building HTML tree..."
+
+ dhelp_parse -r && ret=$? || ret=$?
+
+ if [ ${ret} -eq 0 ]; then
+ echo " done."
+ fi
+ return ${ret}
+}
+
+# create the full text search index file in the background
+#
+delaybuild_search_index ()
+{
+ local ret=0
+
+ # since the pending list is created by dhelp_parse -r, if index file
+ # does not exist, it suffices to do incremental indexing.
+
+ if [ -f /var/lib/dhelp/documents.index ]; then
+ return 0
else
- >&2 echo "Error: ${DHELP_INDEXER} does not exist or is not executable"
- exit 3
+ echo "Reindexing documentation in the background"
+
+ if [ -x ${DHELP_INDEXER} ]; then
+ ${DHELP_INDEXER} && ret=$? || ret=$?
+ return ${ret}
+ else
+ install_msg dhelp err \
+ "Error: ${DHELP_INDEXER} does not exist or is not executable"
+ return 1
+ fi
fi
-fi
+}
-unset DHELP_INDEXER DHELP_POSTCMD DHELP_APTHOOK DHELP_TMP_APTHOOK || true
+#### Main script body ####
+
+# NOTE: do not fail package installation if "cache data" that can be
+# recreated anytime cannot for any reason be created during install.
+
+case $1 in
+configure|abort-upgrade)
+
+ # cleanup artifacts of previous versions
+
+ do_upgrade_cleanup_actions
+
+ # Create and register with ucf our dpkg post-invoke hook.
+
+ register_dpkg_postinvoke_hook
+
+ # Hack to tell if the package is configured, so that third party
+ # packages that call dhelp don't barf (from scrollkeeper package).
+ # It is also checked by dhelp_parse, hence this line must come
+ # _before_ the build_document_index call.
+
+ touch /var/lib/dhelp/configured
+
+ # Create the html document index before registering configuration
+ # snippets with installed web servers.
+
+ if build_document_index; then
+ DHELP_OKINDEX="true"
+ else
+ install_msg dhelp err \
+ "Error: building of the HTML tree failed;" \
+ "check mount options and disk space for '/usr/share/doc/HTML'" \
+ "and run 'dhelp_parse -r' to retry the build process."
+ fi
+
+ # Apache2: copy in both locations, ie for versions < 2.4 and >= 2.4
+
+ cp_ucfregister_file dhelp ${DHELP_CONFDIR}/apache-dhelp.conf \
+ /etc/apache2/conf.d/dhelp
+ cp_ucfregister_file dhelp ${DHELP_CONFDIR}/apache-dhelp.conf \
+ /etc/apache2/conf-available/dhelp.conf
+
+ try_chconf_apache2 "enable" dhelp || true
+
+ # Lighttpd:
+
+ cp_ucfregister_file dhelp ${DHELP_CONFDIR}/lighttpd-dhelp.conf \
+ /etc/lighttpd/conf-available/95-dhelp.conf
+
+ try_chconf_lighttpd "enable" dhelp || true
+
+ # Create the full text search index at the end of postinst.
+
+ if [ "${DHELP_OKINDEX}" = "true" ]; then
+ if delaybuild_search_index; then
+ :
+ else
+ install_msg dhelp err \
+ "Error: delayed indexing failed;" \
+ "run the weekly cron job to recreate the index."
+ fi
+ else
+ install_msg dhelp warning \
+ "Not reindexing documentation due to HTML tree" \
+ "build error; correct the above and run the weekly" \
+ "cron job to recreate the index."
+ fi
+ ;;
+*)
+ ;;
+esac
+
+unset DHELP_INDEXER DHELP_POSTCMD DHELP_APTHOOK || true
+unset DHELP_CONFDIR DHELP_LIBFILE DHELP_OKINDEX || true
-#DEBHELPER#
diff --git a/debian/prerm b/debian/prerm
index 1327bfb..07cf3be 100755
--- a/debian/prerm
+++ b/debian/prerm
@@ -1,18 +1,118 @@
-#!/bin/sh -e
+#!/bin/sh
+#
+# Copyright (C) 2001,2002 Stefan Hornburg (Racke) <racke@linuxia.de>
+# Copyright (C) 2011,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.
+
+set -e
#DEBHELPER#
-rm -rf /var/lib/dhelp
-rm -rf /usr/doc/HTML /usr/share/doc/HTML
-rm -f /var/lib/dhelp/configured
+#### Globals ####
+
+DHELP_APTHOOK=/etc/apt/apt.conf.d/35dhelp
+
+#### Import Library ####
+
+# If old version's prerm fails, our files (and thus the script library)
+# will not be available. Thus, we need to treat this case specially.
+
+case $1 in
+failed-upgrade)
+ ;;
+*)
+ for DHELP_LIBFILE in /usr/share/dhelp/maint-scripts/*.sh; do
+ if [ -f ${DHELP_LIBFILE} ]; then
+ . ${DHELP_LIBFILE}
+ else
+ >&2 echo "Dhelp error: file ${DHELP_LIBFILE} was not found."
+ >&2 echo "Please file a bug report at bugs.debian.org" \
+ "against the dhelp package."
+ fi
+ done
+ ;;
+esac
+
+#### Functions ####
+
+# Cleanup the files installed by the postinst.
+#
+do_removal_cleanup_actions ()
+{
+ # The directories themselves will be removed by dpkg;
+ # cf. our debian/dirs entries.
+
+ # Remove all cache data inside /var/lib/dhelp/tmp
+
+ if [ -d /var/lib/dhelp/tmp ]; then
+ rm --force /var/lib/dhelp/tmp/* || true
+ fi
+
+ # Remove all cache data inside /var/lib/dhelp
+ # Hide the "rm: cannot remove `/var/lib/dhelp/tmp': Is a directory" error.
+
+ if [ -d /var/lib/dhelp ]; then
+ rm --force /var/lib/dhelp/* 2>&1 \
+ | grep --invert-match '/var/lib/dhelp/tmp' || true
+ fi
+
+ # Remove html document index directory contents.
+
+ if [ -d /usr/share/doc/HTML ]; then
+ rm --force --recursive /usr/share/doc/HTML/*
+ fi
+}
+
+#### Main script body ####
+
+case $1 in
+failed-upgrade)
+ # Library is not available; confine ourselves to the bare essentials.
+
+ do_removal_cleanup_actions
+ ;;
+*)
+ # Disable our web server configuration snippets.
+
+ try_chconf_apache2 "disable" dhelp || true
+ try_chconf_lighttpd "disable" dhelp || true
+
+ # Cleanup the files installed by the postinst.
+
+ do_removal_cleanup_actions
+ ;;
+esac
+
+case $1 in
+purge)
+ # Remove and unregister with ucf our web server configuration snippets.
+
+ ucf_unregister_file dhelp /etc/apache2/conf.d/dhelp
+ ucf_unregister_file dhelp /etc/apache2/conf-available/dhelp.conf
+
+ ucf_unregister_file dhelp /etc/lighttpd/conf-available/95-dhelp.conf
+
+ # Remove and unregister with ucf our dpkg post-invoke hook.
-if [ \( "$1" = "upgrade" -o "$1" = "remove" \) \
- -a -L /usr/doc/dhelp ]; then
- rm -f /usr/doc/dhelp
-fi
+ ucf_unregister_file dhelp ${DHELP_APTHOOK}
+ ;;
+*)
+ ;;
+esac
+unset DHELP_APTHOOK DHELP_LIBFILE || true
-if [ \( "$1" = "upgrade" -o "$1" = "remove" \) \
- -a -L /usr/doc/HTML ]; then
- rm -f /usr/doc/HTML
-fi
diff --git a/debian/scripts/files.sh b/debian/scripts/files.sh
new file mode 100644
index 0000000..aa038fc
--- /dev/null
+++ b/debian/scripts/files.sh
@@ -0,0 +1,139 @@
+# File operation 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.
+
+
+# Test executability (implies existence) of a binary in the system's path.
+# ARGS:
+# $1=binary_basename
+#
+is_exec()
+{
+ # First ensure we are not passed an empty argument,
+ # because test -x "" returns success.
+
+ if [ "X${1}" = "X" ]; then
+ return 2
+ fi
+
+ # Then look for the binary location. If not found,
+ # return error, because test -x "" returns success.
+
+ local binary=$(which "${1}" 2>/dev/null)
+
+ if [ "X${binary}" = "X" ]; then
+ return 1
+ fi
+
+ # If the binary is found, return its executable status.
+
+ test -x "${binary}" 2>/dev/null
+}
+
+
+# Ucf-interfacing of generated conffiles helpers.
+# Fall-through behaviour, when ucf is not available:
+# -- install our version of the conffile
+# -- if old conffile exists and is a file, rename old conffile to
+# <conffile>.ucf-old
+# -- if old conffile or <conffile>.ucf-old exists and is a directory,
+# fail.
+
+# Copy a conffile to the filesystem and add it to the ucf and ucfr databases.
+# ARGS:
+# $1=package $2=source $3=destination
+#
+cp_ucfregister_file ()
+{
+ local package="${1}"
+ local srcfile="${2}"
+ local conffile="${3}"
+
+ if is_exec ucf; then
+ ucf --debconf-ok --three-way "${srcfile}" "${conffile}"
+ else
+ # If conffile is a symlink, our move-to-old-then-copy strategy
+ # would make the symlink a normal file; account for this.
+
+ if [ -h "${conffile}" ]; then
+
+ local realconf=$(readlink --no-newline \
+ --canonicalize "${conffile}" || :)
+
+ if [ "X${realconf}" = "X" ]; then
+ >&2 echo "${conffile} is a broken symlink; replacing it"
+ rm --force "${conffile}"
+ else
+ conffile="${realconf}"
+ fi
+ fi
+
+ # Now, after resolving symlinks, check for existence and being a file.
+
+ if [ -e "${conffile}" ]; then
+ if [ -d "${conffile}" ] || [ -d "${conffile}.ucf-old" ]; then
+ >&2 echo "${conffile} is a directory; aborting"
+ return 10
+ fi
+ # We do not use the backup option, because in such a case
+ # we would being accumulating backups on each upgrade.
+
+ mv --force "${conffile}" "${conffile}.ucf-old"
+ fi
+ cp --force --preserve "${srcfile}" "${conffile}"
+ fi
+
+ if is_exec ucfr; then
+ ucfr "${package}" "${conffile}"
+ fi
+}
+
+# Move a (temporary, ie dynamically created) conffile to the filesystem
+# and add it to the ucf and ucfr databases.
+#
+# $1=package $2=source $3=destination
+#
+mv_ucfregister_file ()
+{
+ cp_ucfregister_file "${1}" "${2}" ${3}
+ rm --force "${2}"
+}
+
+# Remove a conffile from the filesystem and the ucf and ucfr databases.
+# ARGS:
+# $1=package $2=conffile
+#
+ucf_unregister_file ()
+{
+ local package="${1}"
+ local conffile="${2}"
+ local ext
+
+ # the '' value is to delete the file itself
+ for ext in '' '~' '%' .bak .ucf-new .ucf-old .ucf-dist; do
+ rm -f "${conffile}${ext}" || true
+ done
+ if is_exec ucf; then
+ ucf --purge "${conffile}"
+ fi
+ if is_exec ucfr; then
+ ucfr --purge "${package}" "${conffile}"
+ fi
+}
+
diff --git a/debian/scripts/httpd.sh b/debian/scripts/httpd.sh
new file mode 100644
index 0000000..6fe318c
--- /dev/null
+++ b/debian/scripts/httpd.sh
@@ -0,0 +1,263 @@
+# 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={enable,disable} $2=package [$3=name_of_snippet_if_different_from_package]
+#
+try_chconf_apache2 ()
+{
+ local action=${1}
+ local package=${2}
+ local confname=${3}
+
+ 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=enmod
+ else
+ confaction=dismod
+ 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
+ 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={enable,disable} $2=package [$3=name_of_snippet_if_different_from_package]
+#
+try_chconf_lighttpd ()
+{
+ local action=${1}
+ local package=${2}
+ local confname=${3}
+
+ 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${2}" != "X" ]; then
+ confname=${2}
+ 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}
+}
+
diff --git a/debian/scripts/info.sh b/debian/scripts/info.sh
new file mode 100644
index 0000000..973d44d
--- /dev/null
+++ b/debian/scripts/info.sh
@@ -0,0 +1,84 @@
+# Information retrieval/display 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.
+
+
+# Return success if package is installed.
+#
+is_pkg_installed ()
+{
+ LC_ALL=C dpkg --status ${1} 2>/dev/null \
+ | grep --quiet '^Status: install ok installed' 2>/dev/null
+ return $?
+}
+
+# Return the package version.
+#
+get_pkg_version ()
+{
+ echo $(LC_ALL=C dpkg --status ${1} 2>/dev/null \
+ | grep '^Version:' 2>/dev/null \
+ | cut --fields=2 --delimiter=' ' 2>/dev/null)
+}
+
+# Return the {major,minor,tail} part of version. Assume version has the form:
+# major.minor.tail
+# The || true handles missing/ill-formed argument cases.
+
+version_major ()
+{
+ expr "${1}" \: '\([^.]\+\)' 2>/dev/null || true
+}
+
+version_minor ()
+{
+ expr "${1}" \: '[^.]\+\.\([^.]\+\)' 2>/dev/null || true
+}
+
+version_tail ()
+{
+ expr "${1}" \: '[^.]\+\.[^.]\+\.\([^.]\+\)' 2>/dev/null || true
+}
+
+# Display and record to syslog (if logger is available) an error message.
+#
+install_msg ()
+{
+ local package=${1}
+ local priority=${2}
+
+ # Remove package and priority from ARGV; then join all args to message.
+
+ shift; shift
+
+ local message="${package}:"
+ local arg
+
+ for arg; do
+ message="${message} ${arg}"
+ done
+
+ # Output to stanard error and to syslog, if logger is available.
+
+ >&2 echo "${message}"
+ if is_exec logger; then
+ logger -p syslog.${priority} -t "${package}" -- "${message}" || true
+ fi
+}
+