Add all Debian changes since 3.0.24-2.
[privoxy.git] / debian / postinst
1 #! /bin/sh
2 # postinst script for privoxy
3 #
4 # see: dh_installdeb(1)
5
6 set -e
7
8 # summary of how this script can be called:
9 #        * <postinst> `configure' <most-recently-configured-version>
10 #        * <old-postinst> `abort-upgrade' <new version>
11 #        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
12 #          <new-version>
13 #        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
14 #          <failed-install-package> <version> `removing'
15 #          <conflicting-package> <version>
16 # for details, see http://www.debian.org/doc/debian-policy/ or
17 # the debian-policy package
18 #
19 # quoting from the policy:
20 #     Any necessary prompting should almost always be confined to the
21 #     post-installation script, and should be protected with a conditional
22 #     so that unnecessary prompting doesn't happen if a package's
23 #     installation fails and the `postinst' is called with `abort-upgrade',
24 #     `abort-remove' or `abort-deconfigure'.
25
26 CONFDIR=/etc/privoxy
27 CONFIG=$CONFDIR/config
28 EXAMPLE_CONFIG=/usr/share/privoxy/config
29
30 . /usr/share/debconf/confmodule
31
32 case "$1" in
33     configure)
34         adduser --quiet --system --home $CONFDIR --no-create-home \
35             --ingroup nogroup --disabled-password privoxy
36         chown -R privoxy:adm /var/log/privoxy
37         chmod 750 /var/log/privoxy
38         chown privoxy $CONFDIR/user.action $CONFDIR/trust
39         [ -f $CONFDIR/match-all.action ] \
40             && chown privoxy $CONFDIR/match-all.action
41
42         db_get privoxy/listen-address || true
43         perl -le '
44                 $done = 0;
45                 while (<STDIN>) {
46                     chomp;
47                     if ($_ =~ m/^\s*listen-address\s+.*/) {
48                         if (!$done) {
49                             foreach (@ARGV) {
50                                 print "listen-address  $_";
51                             }
52                         }
53                         $done = 1;
54                     } else {
55                         print;
56                     }
57                 }' \
58              $RET \
59              < $EXAMPLE_CONFIG > $CONFIG.ucftmp
60         ucf --three-way --debconf-ok $CONFIG.ucftmp $CONFIG
61         ucfr privoxy $CONFIG
62         rm -f $CONFIG.ucftmp
63
64         if [ "x$2" != "x" ] && dpkg --compare-versions "$2" lt "3.0.4"
65         then
66             # Upgrading from a 3.0.3* version
67             chown root $CONFDIR/default.action
68         fi
69
70         if [ "x$2" != "x" ] && dpkg --compare-versions "$2" lt "3.0.7" \
71             && grep -q '^actionsfile [a-z]*[[:space:]]*#.*$' $CONFIG
72         then
73             # Upgrading from version before 3.0.7 where the user kept his old 
74             # (modified) config file:
75             # Try to change   "actionsfile foo"  to  "actionsfile foo.action"
76             # as needed in 3.0.7:
77             sed 's/^actionsfile \([a-z]*\)\([   ]*\#\)/actionsfile \1.action\2/' \
78                 -i.bak $CONFIG
79         fi
80
81         if [ "x$2" != "x" ] && dpkg --compare-versions "$2" lt "3.0.11"
82         then
83             # Upgrading from a version before 3.0.11
84             # Try to work around problems with missing action files
85             if grep -q '^actionsfile.*global.action' $CONFIG
86             then
87                 if [ -e $CONFDIR/global.action ]
88                 then
89                     mv $CONFDIR/global.action $CONFDIR/global.action.dpkg-old
90                 fi
91                 (cd $CONFDIR; ln -s match-all.action global.action)
92             fi
93             if grep -q '^actionsfile.*standard.action' $CONFIG
94             then
95                 if [ -e $CONFDIR/standard.action ]
96                 then
97                     if ! grep -q migration $CONFDIR/standard.action
98                     then
99                         mv $CONFDIR/standard.action \
100                             $CONFDIR/standard.action.dpkg-old
101                         echo "# migration file. Not used in 3.0.11 and newer" \
102                             > $CONFDIR/standard.action
103                     fi
104                 else
105                     echo "# migration file. Not used in 3.0.11 and newer" \
106                         > $CONFDIR/standard.action
107                 fi
108             fi
109         fi
110     ;;
111
112     abort-upgrade|abort-remove|abort-deconfigure)
113
114     ;;
115
116     *)
117         echo "postinst called with unknown argument \`$1'" >&2
118         exit 1
119     ;;
120 esac
121
122 # dh_installdeb will replace this with shell code automatically
123 # generated by other debhelper scripts.
124
125 #DEBHELPER#
126
127 exit 0
128
129