Merge lp:~lynxman/squid-deb-proxy/debhooks into lp:squid-deb-proxy

Proposed by Marc Cluet
Status: Merged
Merged at revision: 46
Proposed branch: lp:~lynxman/squid-deb-proxy/debhooks
Merge into: lp:squid-deb-proxy
Diff against target: 122 lines (+108/-0)
3 files modified
debian/squid-deb-proxy.config (+7/-0)
debian/squid-deb-proxy.postinst (+89/-0)
debian/squid-deb-proxy.templates (+12/-0)
To merge this branch: bzr merge lp:~lynxman/squid-deb-proxy/debhooks
Reviewer Review Type Date Requested Status
Michael Vogt Needs Fixing
Review via email: mp+63391@code.launchpad.net

Description of the change

We added a couple of debconf hooks in order to be able to configure the config file directly from orchestra

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

Thanks for this branch! I like the idea of adding debconf questions to make it easy to enable certain features. I think thats a great idea. I have some comments about the current implementation though.

[..]
> +case "$1" in
> + configure)
> + # Enable or disable PPAs
> + db_get squid-deb-proxy/ppa-enable
> + if [ "${RET}z" != "z" ]

Is this check for empty result really needed? db_get with a boolean
template should always return either "true" or "false"

> + then
> + case "$RET" in
> + n*|N*)

Did you test that this actually works? $RET should be either string
"true" or "false". The buttons in the question whiptail dialog are a
bit misleading as they can be translated, but the db_get value is
always either true or false.

> + if [ -f "/etc/squid-deb-proxy/mirror-dstdomain.acl" ]
> + then
> + mv /etc/squid-deb-proxy/mirror-dstdomain.acl /etc/squid-deb-proxy/.mirror-dstdomain.acl
> + cat /etc/squid-deb-proxy/.mirror-dstdomain.acl | sed 's/ppa.launchpad.net/#ppa.launchpad.net/' > /etc/squid-deb-proxy/mirror-dstdomain.acl
> + rm -f /etc/squid-deb-proxy/.mirror-dstdomain.acl

Is there a advantage to use this over sed -i ? sed will also
create a temp file first so it should be efffectively the same only
shorter (unless I overlook something here?).

There is one more issue with the approach taken. When running
$ dpkg -s squid-deb-proxy
[..]
Conffiles:
 /etc/squid-deb-proxy/mirror-dstdomain.acl c430d3bc4818751ee177515a41456708
[..]

This shows that the two files manipulated are "conffiles". The debian
policy (in appendix E.1) discourages the manipulation of conffiles
from a maintainer script. I think adding a new line to squid.conf
like
acl to_ubuntu_mirrors_user dstdomain "/etc/squid-deb-proxy/mirror-dstdomain-user.acl"
that is then either created empty or with the content like 0.0.0.0
should do the trick (for mirror-dstdomain-user.acl the same, either a
empty file or a file containing ppa). If that is carefully done all
users benefit as they can add their own content there without the
risks of having conffile prompts in the future. Alternatively it could
use include in the acl files. But I'm not sure that this will actually
work in a acl file.

[..]
> +Template: squid-deb-proxy/acl-enable
> +Type: boolean
> +Description: Enable network ACL
> + squid-deb-proxy restricts access to the cache by address range
> + selecting Y in this option will enable a basic private network range
> + selecting N in this option will allow all IPs to access the cache

Maybe something like "all IPs *in the world* to access the cache" or
something like this to ensure the user understands that this opens his
cache for all others. Not that big of a risk because all they can get
is packages but it may costs bandwith etc and the user/admin should
understand the difference.

review: Needs Fixing
Revision history for this message
Marc Cluet (lynxman) wrote :
Download full text (4.0 KiB)

Hi! *waves*

On Jun 7, 2011, at 16:03 , Michael Vogt wrote:

> Review: Needs Fixing
> Thanks for this branch! I like the idea of adding debconf questions to make it easy to enable certain features. I think thats a great idea. I have some comments about the current implementation though.
>
> [..]
>> +case "$1" in
>> + configure)
>> + # Enable or disable PPAs
>> + db_get squid-deb-proxy/ppa-enable
>> + if [ "${RET}z" != "z" ]
>
> Is this check for empty result really needed? db_get with a boolean
> template should always return either "true" or "false"

We've observed that not establishing a "default" will make the variable empty in some cases, that's why we implemented the check for empty result as "good practice" to avoid nasty surprises.

>
>> + then
>> + case "$RET" in
>> + n*|N*)
>
> Did you test that this actually works? $RET should be either string
> "true" or "false". The buttons in the question whiptail dialog are a
> bit misleading as they can be translated, but the db_get value is
> always either true or false.

It works, this example was actually straight from the package maintainer manual.

>
>> + if [ -f "/etc/squid-deb-proxy/mirror-dstdomain.acl" ]
>> + then
>> + mv /etc/squid-deb-proxy/mirror-dstdomain.acl /etc/squid-deb-proxy/.mirror-dstdomain.acl
>> + cat /etc/squid-deb-proxy/.mirror-dstdomain.acl | sed 's/ppa.launchpad.net/#ppa.launchpad.net/' > /etc/squid-deb-proxy/mirror-dstdomain.acl
>> + rm -f /etc/squid-deb-proxy/.mirror-dstdomain.acl
>
> Is there a advantage to use this over sed -i ? sed will also
> create a temp file first so it should be efffectively the same only
> shorter (unless I overlook something here?).

No there's no advantage over just using sed, it's just my disability to use sed without piping from cat, fixing this now

>
> There is one more issue with the approach taken. When running
> $ dpkg -s squid-deb-proxy
> [..]
> Conffiles:
> /etc/squid-deb-proxy/mirror-dstdomain.acl c430d3bc4818751ee177515a41456708
> [..]
>
> This shows that the two files manipulated are "conffiles". The debian
> policy (in appendix E.1) discourages the manipulation of conffiles
> from a maintainer script. I think adding a new line to squid.conf
> like
> acl to_ubuntu_mirrors_user dstdomain "/etc/squid-deb-proxy/mirror-dstdomain-user.acl"
> that is then either created empty or with the content like 0.0.0.0
> should do the trick (for mirror-dstdomain-user.acl the same, either a
> empty file or a file containing ppa). If that is carefully done all
> users benefit as they can add their own content there without the
> risks of having conffile prompts in the future. Alternatively it could
> use include in the acl files. But I'm not sure that this will actually
> work in a acl file.

I've tried that and the deny unfortunately takes precedence, could you give me an example that you'd think works properly?

>
>
> [..]
>> +Template: squid-deb-proxy/acl-enable
>> +Type: boolean
>> +Description: Enable network ACL
>> + squid-deb-proxy restricts access to the c...

Read more...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'debian/squid-deb-proxy.config'
2--- debian/squid-deb-proxy.config 1970-01-01 00:00:00 +0000
3+++ debian/squid-deb-proxy.config 2011-06-03 15:03:29 +0000
4@@ -0,0 +1,7 @@
5+#!/bin/sh -e
6+# A simplified version of debconf's own config script.
7+. /usr/share/debconf/confmodule
8+# Ask for the rsyslog host
9+db_input low squid-deb-proxy/ppa-enable || true
10+db_input low squid-deb-proxy/acl-enable || true
11+db_go
12
13=== added file 'debian/squid-deb-proxy.postinst'
14--- debian/squid-deb-proxy.postinst 1970-01-01 00:00:00 +0000
15+++ debian/squid-deb-proxy.postinst 2011-06-03 15:03:29 +0000
16@@ -0,0 +1,89 @@
17+#!/bin/sh
18+# postinst script for squid-deb-proxy
19+#
20+# see: dh_installdeb(1)
21+
22+set -e
23+
24+# summary of how this script can be called:
25+# * <postinst> `configure' <most-recently-configured-version>
26+# * <old-postinst> `abort-upgrade' <new version>
27+# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
28+# <new-version>
29+# * <postinst> `abort-remove'
30+# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
31+# <failed-install-package> <version> `removing'
32+# <conflicting-package> <version>
33+# for details, see http://www.debian.org/doc/debian-policy/ or
34+# the debian-policy package
35+
36+# A simplified version of debconf's own config script.
37+. /usr/share/debconf/confmodule
38+
39+case "$1" in
40+ configure)
41+
42+ db_get squid-deb-proxy/ppa-enable
43+ if [ "${RET}z" != "z" ]
44+ then
45+ case "$RET" in
46+ n*|N*)
47+ if [ -f "/etc/squid-deb-proxy/mirror-dstdomain.acl" ]
48+ then
49+ mv -f /etc/squid-deb-proxy/mirror-dstdomain.acl /etc/squid-deb-proxy/.mirror-dstdomain.acl
50+ sed 's/ppa.launchpad.net/#ppa.launchpad.net/' /etc/squid-deb-proxy/.mirror-dstdomain.acl > /etc/squid-deb-proxy/mirror-dstdomain.acl
51+ rm -f /etc/squid-deb-proxy/.mirror-dstdomain.acl
52+ fi
53+ ;;
54+ y*|Y*)
55+ if [ -f "/etc/squid-deb-proxy/mirror-dstdomain.acl" ]
56+ then
57+ mv -f /etc/squid-deb-proxy/mirror-dstdomain.acl /etc/squid-deb-proxy/.mirror-dstdomain.acl
58+ sed 's/#ppa.launchpad.net/ppa.launchpad.net/' /etc/squid-deb-proxy/.mirror-dstdomain.acl > /etc/squid-deb-proxy/mirror-dstdomain.acl
59+ rm -f /etc/squid-deb-proxy/.mirror-dstdomain.acl
60+ fi
61+ ;;
62+ esac
63+ fi
64+
65+ db_get squid-deb-proxy/acl-enable
66+ if [ "${RET}z" != "z" ]
67+ then
68+ case "$RET" in
69+ n*|N*)
70+ if [ -f "/etc/squid-deb-proxy/squid-deb-proxy.conf" ]
71+ then
72+ mv -f /etc/squid-deb-proxy/squid-deb-proxy.conf /etc/squid-deb-proxy/.squid-deb-proxy.conf
73+ sed 's/http_access deny all/http_access allow all/' /etc/squid-deb-proxy/.squid-deb-proxy.conf > /etc/squid-deb-proxy/squid-deb-proxy.conf
74+ rm -f /etc/squid-deb-proxy/.squid-deb-proxy.conf
75+ fi
76+ ;;
77+ y*|Y*)
78+ if [ -f "/etc/squid-deb-proxy/squid-deb-proxy.conf" ]
79+ then
80+ mv -f /etc/squid-deb-proxy/squid-deb-proxy.conf /etc/squid-deb-proxy/.squid-deb-proxy.conf
81+ sed 's/http_access allow all/http_access deny all/' /etc/squid-deb-proxy/.squid-deb-proxy.conf > /etc/squid-deb-proxy/squid-deb-proxy.conf
82+ rm -f /etc/squid-deb-proxy/.squid-deb-proxy.conf
83+ fi
84+ ;;
85+ esac
86+ fi
87+
88+ invoke-rc.d squid-deb-proxy restart
89+ ;;
90+
91+ abort-upgrade|abort-remove|abort-deconfigure|triggered)
92+ ;;
93+
94+ *)
95+ echo "postinst called with unknown argument \`$1'" >&2
96+ exit 1
97+ ;;
98+esac
99+
100+# dh_installdeb will replace this with shell code automatically
101+# generated by other debhelper scripts.
102+
103+#DEBHELPER#
104+
105+exit 0
106
107=== added file 'debian/squid-deb-proxy.templates'
108--- debian/squid-deb-proxy.templates 1970-01-01 00:00:00 +0000
109+++ debian/squid-deb-proxy.templates 2011-06-03 15:03:29 +0000
110@@ -0,0 +1,12 @@
111+Template: squid-deb-proxy/ppa-enable
112+Type: boolean
113+Description: Enable PPA caching
114+ squid-deb-proxy by default will not cache ppa repositories
115+ selecting Y in this option will activate ppa repo caching
116+
117+Template: squid-deb-proxy/acl-enable
118+Type: boolean
119+Description: Enable network ACL
120+ squid-deb-proxy restricts access to the cache by address range
121+ selecting Y in this option will enable a basic private network range
122+ selecting N in this option will allow all IPs to access the cache

Subscribers

People subscribed via source and target branches

to all changes: