#!/bin/sh
#
# chkconfig: - 84 16
#
# description:	Privoxy is a web proxy with advanced filtering \
# 	capabilities for protecting privacy, filtering web page content, \
# 	managing cookies, controlling access, and removing ads, banners, \
#	pop-ups and other obnoxious Internet junk. Privoxy has a \
#	very flexible configuration and can be customized to suit individual \
# 	needs and tastes. Privoxy has application for both stand-alone \
# 	systems and multi-user networks.         
#

# Source function library.
. /etc/init.d/functions

# Source networking configuration.
SourceIfNotEmpty /etc/sysconfig/network && [ "$NETWORKING" != no ] || exit

NAME="privoxy"
ROOT="/var/lib/privoxy"

DAEMON="/usr/sbin/$NAME"
CONFIG="/etc/$NAME/config"

[ -x "$DAEMON" -a -r "$ROOT/$CONFIG" ] || exit

LOCKFILE="/var/lock/subsys/$NAME"
RETVAL=0

adjust()
{
	action "Adjusting environment for $NAME:" /etc/chroot.d/$NAME.all
	RETVAL=$?
	return $RETVAL
}

start()
{
	adjust || return
	echo -n "Starting $NAME: "
	daemon "$DAEMON" --chroot --user $NAME "$CONFIG"
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch "$LOCKFILE"
}

stop()
{
	echo -n "Shutting down $NAME: "
	killproc "$DAEMON"
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f "$LOCKFILE"
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart|reload)
		restart
		;;
	adjust)
		adjust
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	status)
		status "$NAME"
		RETVAL=$?
		;;
	*)
		echo "Usage: ${0##*/} {start|stop|reload|restart|condstop|condrestart|adjust|status}"
		RETVAL=1
esac

exit $RETVAL
