2f9959a02a6039b527c0f95a9246b2442613b530
[amavisd-cn.git] / debian / postinst
1 #!/bin/sh
2 # postinst script for amavisd-cn
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
20 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
21
22 case "$1" in
23   configure)
24     # continue below
25   ;;
26
27   abort-upgrade|abort-remove|abort-deconfigure)
28     exit 0
29   ;;
30
31   *)
32     echo "postinst called with unknown argument \`$1'" >&2
33     exit 0
34   ;;
35 esac
36
37 PATH=/bin:/usr/bin:/sbin:/usr/sbin
38 export PATH
39
40 . /usr/share/amavisd-cn/version.sh
41 . /usr/share/carnet-tools/functions.sh
42 . /usr/share/amavisd-cn/variables.sh
43 . /usr/share/amavisd-cn/functions.sh
44
45 mta=postfix
46 . /usr/share/amavisd-cn/postfix.sh
47
48 # $domain will be equal to $host if nothing better can be found
49 cp_get_mx_domain
50 domain=$RET
51
52 update_postfix $*
53
54 # amavisd.conf
55 if [ -f "$ACONFOLD" ]; then
56   cp_echo "CN: Amavisd configuration is now in $ACONF."
57   noisy_backup "$ACONFOLD"
58   rm -f "$ACONFOLD"
59   cp_echo ""
60   cp_echo "CN: Please read /usr/share/doc/amavisd-cn/README.CARNet."
61 elif [ -f "$ACONFOLD.disabled" ]; then
62   noisy_backup "$ACONFOLD.disabled" "$(basename $ACONFOLD)"
63   rm -f "$ACONFOLD.disabled"
64   cp_echo "CN: Please read /usr/share/doc/amavisd-cn/README.CARNet."
65 fi
66
67 if [ -f $ACONF ]; then
68   # add other fixups to function update_conf(), way above
69   update_conf $*
70 fi
71 # nonexistent or empty config
72 if [ ! -f $ACONF -o ! -s $ACONF ]; then
73   # Create fresh config from template
74   conf_from_template
75   restart_daemon=1
76 fi
77
78 # disable SAVI as proven problematic
79 if cp_check_and_sed "^[[:blank:]]*\['Sophos SAVI'" \
80  "s/^[[:blank:]]*\(\['Sophos SAVI', ..sophos_savi \]\)/#\1/" $ACONF; then
81   cp_echo "CN: Disabled SAVI::Perl usage in ${ACONF}."
82   restart_daemon=1
83 fi
84
85 check_and_add_alias virusalert root
86 check_and_add_alias spamalert root
87
88 # ovo je rijeseno u spamassassin-cn, i ovdje nije potrebno, stoga brisemo
89 if [ -f $AHOME/.spamassassin/user_prefs ] ; then
90   user_prefs_temp=$(mktemp /tmp/user_prefs.XXXXXX)
91   cat > $user_prefs_temp <<-EEND
92         bayes_path              $AHOME/.spamassassin/bayes
93         bayes_auto_expire       0
94         auto_whitelist_path     $AHOME/.spamassassin/auto-whitelist
95         EEND
96   if cmp -s $user_prefs_temp $AHOME/.spamassassin/user_prefs; then
97     rm -f $AHOME/.spamassassin/user_prefs
98   fi
99   rm -f $user_prefs_temp
100 fi
101
102 # No sysvinit order fixes
103 :
104
105 # Fix missing redirection in cron files for amavisd-new-cronjob
106 add_redirection /etc/cron.d/amavisd-new
107
108 # Cleanup and finalization
109 if dpkg --compare-versions "$2" lt 2:20030616p10-4; then
110   update-rc.d -f amavisd remove > /dev/null
111   restart_daemon=1
112   chown_ahome=1
113   # a complicated way to say chmod 750
114   dpkg-statoverride --remove $AHOME > /dev/null || true
115   dpkg-statoverride --update --add amavis amavis 750 $AHOME
116 fi
117
118 if [ -n "$chown_ahome" ]; then
119   # might be slow
120   echo -n "CN: Fixing ownership in /var/*/amavis... "
121   chown -R amavis:amavis $AHOME /var/run/amavis || true
122   echo "done."
123   cp_echo -mailonly "CN: Fixed ownerships in /var/*/amavis."
124 fi
125
126 # kill naughty pyzor descendants -- XXX needed for 2.4 or not?
127 if dpkg --compare-versions "$2" lt 2:20030616p10-7 && \
128   pgrep -u amavis -f '/usr/bin/pyzor check' > /dev/null; then
129   if [ -x "/etc/init.d/amavisd-cn" ]; then
130     if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
131       invoke-rc.d amavisd-cn stop
132     else
133       /etc/init.d/amavisd-cn stop
134     fi
135   fi
136   pkill -9 -u amavis -f '/usr/bin/pyzor check' > /dev/null || true
137   if [ -x "/etc/init.d/amavisd-cn" ]; then
138     if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
139       invoke-rc.d amavisd-cn start
140     else
141       /etc/init.d/amavisd-cn start
142     fi
143   fi
144   restart_daemon=
145   restart_mta=
146 fi
147
148 # register for automatic start
149 update-rc.d -f amavis remove >/dev/null || true
150 update-rc.d amavisd-cn defaults 19 21 >/dev/null
151
152 # START AMAVISD
153 # about a half of amavisd-cn script is here
154 #if [ "$restart_daemon" -a -x /etc/init.d/amavis.amavisd-new ]; then
155 #  if [ -x "/etc/init.d/amavis.amavisd-new" ]; then
156 #    if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
157 #      invoke-rc.d amavis.amavisd-new restart
158 #    else
159 #      /etc/init.d/amavis.amavisd-new restart
160 #    fi
161 #  fi
162 #fi
163 ## always check that the daemons are running
164 #if ! wait_for_fds amavis; then
165 #  if [ -x "/etc/init.d/amavis.amavisd-new" ]; then
166 #    if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
167 #      invoke-rc.d amavis.amavisd-new start
168 #    else
169 #      /etc/init.d/amavis.amavisd-new start
170 #    fi
171 #  fi
172 #  wait_for_fds amavis
173 #fi
174 #if [ "$restart_mta" ]; then
175 #  if [ -x "/etc/init.d/$mta" ]; then
176 #    if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
177 #      invoke-rc.d $mta restart
178 #    else
179 #      /etc/init.d/$mta restart
180 #    fi
181 #  fi
182 #fi
183
184 restart_daemon="1"
185
186 if [ "$restart_daemon" -a -x /etc/init.d/amavisd-cn ]; then
187   if [ -x "/etc/init.d/amavisd-cn" ]; then
188     if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
189       invoke-rc.d amavisd-cn restart
190     else
191       /etc/init.d/amavisd-cn restart
192     fi
193   fi
194 fi
195 # always check that the daemons are running
196
197 # this needs to be updated when $CRONTAB file changes
198 if dpkg --compare-versions "$2" lt "2:20030616p10-4"; then
199   cp_echo ""
200   cp_echo "CN: Deleting temp files older than 1 day every day at 01:35 AM"
201   cp_echo "CN: Deleting spam-mail  older than 7 days every day at 03:15 AM"
202   cp_echo "CN: Deleting virus-mail older than 7 days every day at 04:25 AM"
203   cp_echo "    (can be changed in $CRONTAB)"
204 fi
205 # This script is, hopefully, not needed any more.  Hide it.
206 ## display this message just once... maybe use debconf instead
207 #if dpkg --compare-versions "$2" lt "2:20030616p10-4"; then
208 #  cp_echo ""
209 #  cp_echo "CN: To stop, start or restart all of the clamav+amavis+mta components,"
210 #  cp_echo "CN: use the /etc/init.d/amavisd-cn script."
211 #fi
212 if [ "$failed" ]; then
213   cp_echo ""
214   cp_echo "CN: Services $failed failed to restart!"
215   cp_echo "CN: Please check and start manually if needed."
216 fi
217
218 # Upgrade, but no automatically changed config;
219 # warn if new template available
220 if [ -n "$2" -a -z "$changed_config" ] && \
221    dpkg --compare-versions "$2" lt "$TMPLVERSION"; then
222   cp_echo ""
223   cp_echo "CN: It seems you have upgraded this package from version $2."
224   cp_echo "CN: Configuration template for $mta was modified in version ${TMPLVERSION}."
225   cp_echo "    You might want to review the changes, or simply copy the new template and"
226   cp_echo "    and replace the _CN_DOMAIN_ string with an adequate value:"
227   cp_echo "    cp $ACONFTMPL $ACONF"
228   cp_echo "    perl -pi -e 's/_CN_DOMAIN_/$domain/g' $ACONF"
229 fi
230
231 # Delete old conffiles...
232 for conffile in /etc/logcheck/violations.ignore.d/amavisd-new \
233          /etc/logcheck/ignore.d.server/amavisd-new \
234          /etc/logcheck/ignore.d.workstation/amavisd-new \
235          /etc/cron.daily/amavisd-new; do
236   if [ -f ${conffile} ]; then
237     cp_echo "CN: Deleting old conffile ${conffile}..."
238     rm -f ${conffile}
239   fi
240 done
241
242 cp_mail $PKG $VERSION
243
244 exit 0
245
246 #DEBHELPER#