#!/bin/sh set -e [ "$1" = "configure" ] || exit 0 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx # Load CARNet Tools . /usr/share/carnet-tools/functions.sh hostname=`hostname -f` cron="/etc/cron.d/amavis-stats" htpasswd="/usr/share/amavis-stats/.htpasswd" aconf="/etc/amavis-stats/apache.conf" # these two are used in mail package="amavis-stats-cn" if [ ! -f $htpasswd ]; then passwd=`makepasswd` htpasswd -bc $htpasswd admin $passwd 2> /dev/null cp_echo "CN: amavis-stats URL is http://$hostname/amavis-stats/" cp_echo "CN: User: admin" cp_echo "CN: Password: $passwd" cp_echo "CN: Use \"htpasswd $htpasswd admin\" to change it." cp_echo "" fi # find out where the logs might lie cant_figure_out() { cp_echo "CN: Can't figure out log file, edit $cron yourself!" 1>&2 } if [ -f /etc/rsyslog.conf ]; then sl=/etc/rsyslog.conf else sl=/etc/syslog.conf fi if grep -q /var/log/mail.info $cron; then if [ ! -e "$sl" ]; then # no syslog.conf or rsyslog.conf cant_figure_out elif pgrep syslog-ng > /dev/null; then # syslog-ng, I'm not parsing _that_. cant_figure_out elif ! grep -q '^mail.info[ ][ ]*-?/var/log/mail.info' $sl; then # where oh where does mail.info go to? log=$(awk '$1 == "mail.info" {print $2}' < $sl | sed 's/^-//' | head -1) [ -z "$log" ] && \ log=$(awk '$1 == "mail.*" {print $2}' < $sl | sed 's/^-//' | head -1) [ -z "$log" ] && \ log=$(awk '$1 ~ /mail\.info/ {print $2}' < $sl | sed 's/^-//' | head -1) [ -z "$log" ] && \ log=$(awk '$1 ~ /mail\.\*/ {print $2}' < $sl | sed 's/^-//' | head -1) if [ -z "$log" ]; then cant_figure_out else sed "s,/var/log/mail.info,$log,g" < "$cron" > "${cron}.dpkg-tmp" if ! cmp -s "${cron}.dpkg-tmp" "$cron"; then cp "${cron}.dpkg-tmp" "$cron" cp_echo "CN: ${log} set as log file in ${cron}." fi rm "${cron}.dpkg-tmp" fi fi fi # ash's [ continues after -a, so we need && here if [ -f "$log" ] && [ "$(dirname $log)" = "/var/log/mail" ]; then logdirgroup=$(ls -ld /var/log/mail | awk '{print $4}') if [ "$logdirgroup" != "adm" ]; then # whyever was it not adm? on woody it's mail, on sarge smmsp...? # and i'm not going to give amavis-stats privileges for those cp_echo "CN: chgrp adm /var/log/mail (was \"$logdirgroup\")." chgrp adm /var/log/mail #chgrp smmsp /var/log/mail #addgroup amavis-stats smmsp > /dev/null fi fi if ! grep -iq 'valid-user' $aconf; then cat > ${aconf}.dpkg-tmp < Options +FollowSymLinks AllowOverride None order allow,deny allow from all AuthType Basic AuthName amavis-stats AuthUserFile $htpasswd require valid-user EOF # If default debian file, don't bother to save it if [ "$(md5sum $aconf|awk '{print $1}')" != "b6820ee83bc5b6386c72428f42950b6b" ]; then bak="$aconf.dpkg-old.$(date '+%Y-%m-%d')" if [ ! -f "$bak" ]; then cp -p "${aconf}" "$bak" cp_echo "CN: Old apache config saved as \"$bak\"." fi fi cp "${aconf}.dpkg-tmp" "$aconf" rm "${aconf}.dpkg-tmp" cp_echo "CN: Forced valid-user for amavis-stats web." reload=1 fi cp_mail $package if [ ! -L /etc/apache2/conf.d/amavis-stats-cn.conf -a ! -f /etc/apache2/conf.d/amavis-stats-cn.conf ]; then ln -sf /etc/amavis-stats/apache.conf /etc/apache2/conf.d/amavis-stats-cn.conf reload_apache2="yes" fi if [ "$reload_apache2" = "yes" ]; then if [ -x /usr/sbin/invoke-rc.d ]; then [ -x /etc/init.d/apache2 ] && invoke-rc.d apache2 reload || true else [ -x /etc/init.d/apache2 ] && /etc/init.d/apache2 reload || true fi fi