#! /bin/sh # This file is part of mailfrom filter. # Copyright (C) 2005, 2006 Sergey Poznyakoff # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA PIDFILE= DAEMON= ARGS="" PS="ps axwwww" mailfromd_start() { if mailfromd_status -q; then cat >&2 <<-EOT Mailfromd seems to be running. Try \`$0 status' to examine, or \`$0 restart' to force restart. EOT exit 1 fi echo "Starting mailfromd..." rm -f $PIDFILE if eval $DAEMON $ARGS ; then if [ ! -r $PIDFILE ]; then sleep 1 test -r $PIDFILE || echo "mailfromd NOT started" >&2 fi else echo "mailfromd failed to start" >&2 fi } mailfromd_stop() { echo "Stopping mailfromd..." if [ -r $PIDFILE ]; then PID=`head -n 1 $PIDFILE` kill -TERM -$PID 2>/dev/null N=0 while [ -r $PIDFILE ] do N=$(($N + 1)) if [ $N -gt 5 ]; then break fi sleep 1 done if [ -r $PIDFILE ]; then echo "Still running. Killing it..." >&2 kill -KILL $PID 2>/dev/null rm $PIDFILE fi else echo "mailfromd is not running" >&2 fi } mailfromd_status() { if [ -r $PIDFILE ]; then PID=`head -n 1 $PIDFILE` if [ "$1" != "-q" ]; then echo "mailformd appears to be running at $PID" fi else PID='[0-9][0-9]*' fi $PS | grep "[0-9]:[0-9][0-9] $DAEMON " | while read pid tt stat time command do echo $pid $command done | grep $1 "$PID $command" } mailfromd_configtest() { case $# in 0) CFGOPT=;; 1) CFGOPT=$1;; *) echo "$0: too many arguments, try \`$0 help' for more info" >&2 exit 1;; esac $DAEMON $CFGOPT --lint } export_cf_macros() { echo "O Milter.macros.$1=$2" } export_mc_macros() { un=`echo $1 | tr a-z A-Z` echo "define(\`confMILTER_MACROS_$un', ifdef(\`confMILTER_MACROS_$un',\`confMILTER_MACROS_$un\`,' ')\`$2')" } mailfromd_macros() { EXPORT=export_mc_macros CFGOPT= while [ $# -ne 0 ] do case $1 in -c|--cf) EXPORT=export_cf_macros; shift;; --) shift; break;; -*) echo "$0: unknown command line option: $1" >&2; exit 1;; *) if [ $# -eq 1 ]; then if [ -r $1 ]; then CFGOPT="$1" else echo "$0: \`$1' does not exist or is unreadable" >&2 exit 1 fi break else echo "$0: too many arguments, try \`$0 help' for more info" >&2 exit 1 fi;; esac done IOUTPUT= $DAEMON $CFGOPT --dump-macros | while read state rest do if [ -z "$IOTPUT" ]; then if [ "$state" != "helo" ]; then $EXPORT helo i else rest="i, $rest" fi IOTPUT=yes fi $EXPORT $state "$rest" done exit 0 } case $1 in start) mailfromd_start;; stop) mailfromd_stop;; restart) mailfromd_stop sleep 1 mailfromd_start;; status) mailfromd_status;; configtest) shift mailfromd_configtest $@;; macros) shift mailfromd_macros $@;; help) cat <&2 echo "Try \`$0 help' for more info" >&2 esac # End of rc.mailfromd