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