#!/bin/sh
#
#
#LocINFO Startup for Fetchmail
#

killproc() {		# kill the named process(es)
	pid=`/usr/bin/ps -e |
	     /usr/bin/grep $1 |
	     /usr/bin/sed -e 's/^  *//' -e 's/ .*//'`
	[ "$pid" != "" ] && kill $pid
}

case "$1" in
'start')
	if [ -f /etc/fetchmail.users ]
	then
		while read User
		do
		    if id $User >/dev/null 2>&1
		    then
			/bin/su $User -c "/usr/local/bin/fetchmail -d 600 -L /tmp/$User.fetchmail.log -v"
		    fi
		done </etc/fetchmail.users
	fi
	;;
'stop')
	killproc fetchmai
	;;
*)
	echo "Usage: /etc/init.d/fmail { start | stop }"
	;;
esac
exit 0
