Update debian directory to 3.0.26-6 status.
[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 privoxy:adm /var/log/privoxy
37         [ -f /var/log/privoxy/logfile ] \
38             && chown privoxy:adm /var/log/privoxy/logfile
39         chmod 750 /var/log/privoxy
40         chown privoxy $CONFDIR/user.action $CONFDIR/trust
41         [ -f $CONFDIR/match-all.action ] \
42             && chown privoxy $CONFDIR/match-all.action
43
44         db_get privoxy/listen-address || true
45         perl -le '
46                 $done = 0;
47                 while (<STDIN>) {
48                     chomp;
49                     if ($_ =~ m/^\s*listen-address\s+.*/) {
50                         if (!$done) {
51                             foreach (@ARGV) {
52                                 print "listen-address  $_";
53                             }
54                         }
55                         $done = 1;
56                     } else {
57                         print;
58                     }
59                 }' \
60              $RET \
61              < $EXAMPLE_CONFIG > $CONFIG.ucftmp
62         ucf --three-way --debconf-ok $CONFIG.ucftmp $CONFIG
63         ucfr privoxy $CONFIG
64         rm -f $CONFIG.ucftmp
65         db_stop
66
67         if [ "x$2" != "x" ] && dpkg --compare-versions "$2" lt "3.0.4"
68         then
69             # Upgrading from a 3.0.3* version
70             chown root $CONFDIR/default.action
71         fi
72
73         if [ "x$2" != "x" ] && dpkg --compare-versions "$2" lt "3.0.7" \
74             && grep -q '^actionsfile [a-z]*[[:space:]]*#.*$' $CONFIG
75         then
76             # Upgrading from version before 3.0.7 where the user kept his old 
77             # (modified) config file:
78             # Try to change   "actionsfile foo"  to  "actionsfile foo.action"
79             # as needed in 3.0.7:
80             sed 's/^actionsfile \([a-z]*\)\([   ]*\#\)/actionsfile \1.action\2/' \
81                 -i.bak $CONFIG
82         fi
83
84         if [ "x$2" != "x" ] && dpkg --compare-versions "$2" lt "3.0.11"
85         then
86             # Upgrading from a version before 3.0.11
87             # Try to work around problems with missing action files
88             if grep -q '^actionsfile.*global.action' $CONFIG
89             then
90                 if [ -e $CONFDIR/global.action ]
91                 then
92                     mv $CONFDIR/global.action $CONFDIR/global.action.dpkg-old
93                 fi
94                 (cd $CONFDIR; ln -s match-all.action global.action)
95             fi
96             if grep -q '^actionsfile.*standard.action' $CONFIG
97             then
98                 if [ -e $CONFDIR/standard.action ]
99                 then
100                     if ! grep -q migration $CONFDIR/standard.action
101                     then
102                         mv $CONFDIR/standard.action \
103                             $CONFDIR/standard.action.dpkg-old
104                         echo "# migration file. Not used in 3.0.11 and newer" \
105                             > $CONFDIR/standard.action
106                     fi
107                 else
108                     echo "# migration file. Not used in 3.0.11 and newer" \
109                         > $CONFDIR/standard.action
110                 fi
111             fi
112         fi
113     ;;
114
115     abort-upgrade|abort-remove|abort-deconfigure)
116
117     ;;
118
119     *)
120         echo "postinst called with unknown argument \`$1'" >&2
121         exit 1
122     ;;
123 esac
124
125 # dh_installdeb will replace this with shell code automatically
126 # generated by other debhelper scripts.
127
128 #DEBHELPER#
129
130 exit 0
131
132