0c0ac9ffb9bf07ffca587b4457c18357cc092435
[amavisd-cn.git] / debian / postinst
1 #!/bin/sh
2
3 set -e
4
5 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
6
7 case "$1" in
8   configure)
9     # continue below
10   ;;
11
12   abort-upgrade|abort-remove|abort-deconfigure)
13     exit 0
14   ;;
15
16   *)
17     echo "postinst called with unknown argument \`$1'" >&2
18     exit 0
19   ;;
20 esac
21
22 PATH=/bin:/usr/bin:/sbin:/usr/sbin
23 export PATH
24
25 . /usr/share/amavisd-cn/version.sh
26 . /usr/share/carnet-tools/functions.sh
27 . /usr/share/amavisd-cn/variables.sh
28 . /usr/share/amavisd-cn/functions.sh
29
30 # Place configuration tweaks done on upgrades into this function
31 update_conf() {
32   [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
33   # placeholder.
34   # remember to set changed_config=1 and restart_daemon=1 if necessary
35   #:
36   if dpkg --compare-versions "$1" lt 3:2.4.2-3; then
37     conf_from_template
38   fi
39 }
40
41 mta=postfix
42 . /usr/share/amavisd-cn/postfix.sh
43
44 # $domain will be equal to $host if nothing better can be found
45 cp_get_mx_domain
46 domain=$RET
47
48 update_postfix
49
50 # amavisd.conf
51 if [ -f "$ACONFOLD" ]; then
52   cp_echo "CN: Amavisd configuration is now in $ACONF."
53   noisy_backup "$ACONFOLD"
54   rm -f "$ACONFOLD"
55   cp_echo ""
56   cp_echo "CN: Please read /usr/share/doc/amavisd-cn/README.CARNet."
57 elif [ -f "$ACONFOLD.disabled" ]; then
58   noisy_backup "$ACONFOLD.disabled" "$(basename $ACONFOLD)"
59   rm -f "$ACONFOLD.disabled"
60   cp_echo "CN: Please read /usr/share/doc/amavisd-cn/README.CARNet."
61 fi
62
63 if [ -f $ACONF ]; then
64   # add other fixups to function update_conf(), way above
65   update_conf $*
66 fi
67 # nonexistent or empty config
68 if [ ! -f $ACONF -o ! -s $ACONF ]; then
69   # Create fresh config from template
70   conf_from_template
71 fi
72
73 # check for SAVI:
74 # if not there, comment it out, if there, uncomment and restart
75 if ! dpkg -l libsavi-perl 2> /dev/null | egrep -q '^.i' || ! [ -f /usr/lib/libsavi.so ]; then
76   if cp_check_and_sed "^\['Sophos SAVI'" \
77      "s/^\(\['Sophos SAVI', ..sophos_savi \]\)/#\1/" $ACONF; then
78     cp_echo "CN: Disabled SAVI::Perl usage in ${ACONF}."
79     cp_echo "    To enable it, run sophos-sweep-update, uncomment and restart amavis."
80   fi
81 else
82   if cp_check_and_sed "^#\['Sophos SAVI'" \
83      "s/^#\(\['Sophos SAVI', ..sophos_savi \]\)/\1/" $ACONF; then
84     cp_echo "CN: Enabled SAVI::Perl usage in ${ACONF}."
85     restart_daemon=1
86   fi
87 fi
88
89 check_and_add_alias virusalert root
90 check_and_add_alias spamalert root
91
92 # ovo je rijeseno u spamassassin-cn, i ovdje nije potrebno, stoga brisemo
93 if [ -f $AHOME/.spamassassin/user_prefs ] ; then
94   user_prefs_temp=$(mktemp /tmp/user_prefs.XXXXXX)
95   cat > $user_prefs_temp <<-EEND
96         bayes_path              $AHOME/.spamassassin/bayes
97         bayes_auto_expire       0
98         auto_whitelist_path     $AHOME/.spamassassin/auto-whitelist
99         EEND
100   if cmp -s $user_prefs_temp $AHOME/.spamassassin/user_prefs; then
101     rm -f $AHOME/.spamassassin/user_prefs
102   fi
103   rm -f $user_prefs_temp
104 fi
105
106 # No sysvinit order fixes
107 :
108
109 # Cleanup and finalization
110 if dpkg --compare-versions "$2" lt 2:20030616p10-4; then
111   update-rc.d -f amavisd remove > /dev/null
112   restart_daemon=1
113   chown_ahome=1
114   # a complicated way to say chmod 750
115   dpkg-statoverride --remove $AHOME > /dev/null || true
116   dpkg-statoverride --update --add amavis amavis 750 $AHOME
117 fi
118
119 if [ -n "$chown_ahome" ]; then
120   # might be slow
121   echo -n "CN: Fixing ownership in /var/*/amavis... "
122   chown -R amavis:amavis $AHOME /var/run/amavis || true
123   echo "done."
124   cp_echo -mailonly "CN: Fixed ownerships in /var/*/amavis."
125 fi
126
127 # kill naughty pyzor descendants -- XXX needed for 2.4 or not?
128 if dpkg --compare-versions "$2" lt 2:20030616p10-7 && \
129     pgrep -u amavis -f '/usr/bin/pyzor check' > /dev/null; then
130   /etc/init.d/amavisd-cn stop
131   pkill -9 -u amavis -f '/usr/bin/pyzor check' > /dev/null || true
132   /etc/init.d/amavisd-cn start
133   restart_daemon=
134   restart_mta=
135 fi
136
137 # START AMAVISD
138 # about a half of amavisd-cn script is here
139 if [ "$restart_daemon" -a -x /etc/init.d/amavis.amavisd-new ]; then
140   /etc/init.d/amavis.amavisd-new restart
141 fi
142 # always check that the daemons are running
143 if ! wait_for_fds amavis; then
144   /etc/init.d/amavis.amavisd-new start
145   wait_for_fds amavis
146 fi
147 if [ "$restart_mta" ]; then
148   /etc/init.d/$mta restart
149 fi
150
151 # this needs to be updated when $CRONTAB file changes
152 if dpkg --compare-versions "$2" lt "2:20030616p10-4"; then
153   cp_echo ""
154   cp_echo "CN: Deleting temp files older than 1 day every day at 01:35 AM"
155   cp_echo "CN: Deleting spam-mail  older than 7 days every day at 03:15 AM"
156   cp_echo "CN: Deleting virus-mail older than 7 days every day at 04:25 AM"
157   cp_echo "    (can be changed in $CRONTAB)"
158 fi
159 # This script is, hopefully, not needed any more.  Hide it.
160 ## display this message just once... maybe use debconf instead
161 #if dpkg --compare-versions "$2" lt "2:20030616p10-4"; then
162 #  cp_echo ""
163 #  cp_echo "CN: To stop, start or restart all of the clamav+amavis+mta components,"
164 #  cp_echo "CN: use the /etc/init.d/amavisd-cn script."
165 #fi
166 if [ "$failed" ]; then
167   cp_echo ""
168   cp_echo "CN: Services $failed failed to restart!"
169   cp_echo "CN: Please check and start manually if needed."
170 fi
171
172 # Upgrade, but no automatically changed config;
173 # warn if new template available
174 if [ -n "$2" -a -z "$changed_config" ] && \
175    dpkg --compare-versions "$2" lt "$TMPLVERSION"; then
176   cp_echo ""
177   cp_echo "CN: It seems you have upgraded this package from version $2."
178   cp_echo "CN: Configuration template for $mta was modified in version ${TMPLVERSION}."
179   cp_echo "    You might want to review the changes, or simply copy the new template and"
180   cp_echo "    and replace the _CN_DOMAIN_ string with an adequate value:"
181   cp_echo "    cp $ACONFTMPL $ACONF"
182   cp_echo "    perl -pi -e 's/_CN_DOMAIN_/$domain/g' $ACONF"
183 fi
184
185 cp_mail $PKG $VERSION