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