On 03/20/2016 12:18 PM, Roland Rosenfeld wrote: > At the moment I don't have a solid implementation with sed or awk for > the latter, will think about it (and I'm open for support...).
Hi Roland, It seemed like this might be easier to implement with a perl snippet. I've updated my patch with a suggested implementation. I'm fairly new to perl though, so there may be room for improvement. Regards, James
From d4636a73a69755af4fa85f8a4cb722683bff8852 Mon Sep 17 00:00:00 2001 From: James Valleroy <[email protected]> Date: Sat, 2 Apr 2016 20:46:18 -0400 Subject: [PATCH] Add debconf support to set listen-address. --- debian/config | 25 +++++++++++++++++++++++++ debian/control | 3 +++ debian/install | 1 + debian/po/POTFILES.in | 1 + debian/po/templates.pot | 24 ++++++++++++++++++++++++ debian/postinst | 25 +++++++++++++++++++++++++ debian/postrm | 10 ++++++++++ debian/rules | 1 - debian/templates | 4 ++++ 9 files changed, 93 insertions(+), 1 deletion(-) create mode 100755 debian/config create mode 100644 debian/install create mode 100644 debian/po/POTFILES.in create mode 100644 debian/po/templates.pot create mode 100644 debian/templates diff --git a/debian/config b/debian/config new file mode 100755 index 0000000..a414300 --- /dev/null +++ b/debian/config @@ -0,0 +1,25 @@ +#!/bin/sh +set -e + +. /usr/share/debconf/confmodule + +CONFIG=/etc/privoxy/config + +# Get current configuration. +if [ -e $CONFIG ]; then + LISTENADDRESS=$(perl -le ' + my @listens; + while (<STDIN>) { + chomp; + if ($_ =~ m/^\s*listen-address\s+(\S+)/) { + push @listens, $1; + } + } + print "@listens\n";' \ + < $CONFIG) + + db_set privoxy/listen-address "$LISTENADDRESS" +fi + +db_input medium privoxy/listen-address || true +db_go || true diff --git a/debian/control b/debian/control index 6c9d80e..6068047 100644 --- a/debian/control +++ b/debian/control @@ -13,6 +13,7 @@ Build-Depends: autoconf, jade, libpcre3-dev, man2html, + po-debconf, sgmlspl, sp, w3m, @@ -23,8 +24,10 @@ Homepage: http://www.privoxy.org/ Package: privoxy Architecture: any Depends: adduser, + debconf, logrotate, lsb-base (>= 3.2-13), + ucf, ${misc:Depends}, ${perl:Depends}, ${shlibs:Depends} diff --git a/debian/install b/debian/install new file mode 100644 index 0000000..a1729f0 --- /dev/null +++ b/debian/install @@ -0,0 +1 @@ +config usr/share/privoxy diff --git a/debian/po/POTFILES.in b/debian/po/POTFILES.in new file mode 100644 index 0000000..98e8416 --- /dev/null +++ b/debian/po/POTFILES.in @@ -0,0 +1 @@ +[type: gettext/rfc822deb] templates \ No newline at end of file diff --git a/debian/po/templates.pot b/debian/po/templates.pot new file mode 100644 index 0000000..c8a2543 --- /dev/null +++ b/debian/po/templates.pot @@ -0,0 +1,24 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: privoxy\n" +"Report-Msgid-Bugs-To: [email protected]\n" +"POT-Creation-Date: 2015-09-05 19:17-0400\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <[email protected]>\n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#. Type: string +#. Description +#: ../templates:1001 +msgid "Address and TCP port on which Privoxy will listen for client requests:" +msgstr "" diff --git a/debian/postinst b/debian/postinst index f55b3c8..f79ccb1 100644 --- a/debian/postinst +++ b/debian/postinst @@ -25,6 +25,9 @@ set -e CONFDIR=/etc/privoxy CONFIG=$CONFDIR/config +EXAMPLE_CONFIG=/usr/share/privoxy/config + +. /usr/share/debconf/confmodule case "$1" in configure) @@ -36,6 +39,28 @@ case "$1" in [ -f $CONFDIR/match-all.action ] \ && chown privoxy $CONFDIR/match-all.action + db_get privoxy/listen-address || true + perl -le ' + $done = 0; + while (<STDIN>) { + chomp; + if ($_ =~ m/^\s*listen-address\s+.*/) { + if (!$done) { + foreach (@ARGV) { + print "listen-address $_"; + } + } + $done = 1; + } else { + print; + } + }' \ + $RET \ + < $EXAMPLE_CONFIG > $CONFIG.ucftmp + ucf --three-way --debconf-ok $CONFIG.ucftmp $CONFIG + ucfr privoxy $CONFIG + rm -f $CONFIG.ucftmp + if [ "x$2" != "x" ] && dpkg --compare-versions "$2" lt "3.0.4" then # Upgrading from a 3.0.3* version diff --git a/debian/postrm b/debian/postrm index 3b761d0..afd3038 100644 --- a/debian/postrm +++ b/debian/postrm @@ -21,7 +21,17 @@ set -e case "$1" in purge) # deluser --quiet privoxy + if [ -x "$(which ucf 2>/dev/null)" ]; then + ucf --purge /etc/privoxy/config + fi + if [ -x "$(which ucfr 2>/dev/null)" ]; then + ucfr --purge privoxy /etc/privoxy/config + fi rm -rf /var/log/privoxy /etc/privoxy + if [ -e /usr/share/debconf/confmodule ]; then + . /usr/share/debconf/confmodule + db_purge + fi ;; remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) diff --git a/debian/rules b/debian/rules index 113dadb..c876a5a 100755 --- a/debian/rules +++ b/debian/rules @@ -51,7 +51,6 @@ override_dh_auto_clean: override_dh_auto_install: install -m 0755 privoxy $(DEBDIR)/usr/sbin/privoxy - install -m 644 config $(DEBDIR)/etc/privoxy/config install -m 0644 default.action $(DEBDIR)/etc/privoxy/default.action install -m 0644 match-all.action $(DEBDIR)/etc/privoxy/match-all.action install -m 0644 user.action $(DEBDIR)/etc/privoxy/user.action diff --git a/debian/templates b/debian/templates new file mode 100644 index 0000000..b42052b --- /dev/null +++ b/debian/templates @@ -0,0 +1,4 @@ +Template: privoxy/listen-address +Type: string +Default: localhost:8118 +_Description: Address and TCP port on which Privoxy will listen for client requests: -- 2.8.0.rc3
signature.asc
Description: OpenPGP digital signature

