-Rewrote script config section.
[privoxy.git] / privoxy-generic.init
1 #!/bin/sh
2
3 #  ********************************************************************
4
5 #  File        :  $Source: /cvsroot/ijbswa/current/privoxy-generic.init,v $
6
7 #  Purpose     :  This shell script takes care of starting and stopping
8 #                 privoxy.
9
10 #  Copyright   :  Written by and Copyright (C) 2001,2002 the SourceForge
11 #                 Privoxy team. http://www.privoxy.org/
12
13 #                 Based on the Internet Junkbuster originally written
14 #                 by and Copyright (C) 1997 Anonymous Coders and
15 #                 Junkbusters Corporation.  http://www.junkbusters.com
16
17 #                 This program is free software; you can redistribute it
18 #                 and/or modify it under the terms of the GNU General
19 #                 Public License as published by the Free Software
20 #                 Foundation; either version 2 of the License, or (at
21 #                 your option) any later version.
22
23 #                 This program is distributed in the hope that it will
24 #                 be useful, but WITHOUT ANY WARRANTY; without even the
25 #                 implied warranty of MERCHANTABILITY or FITNESS FOR A
26 #                 PARTICULAR PURPOSE.  See the GNU General Public
27 #                 License for more details.
28
29 #                 The GNU General Public License should be included with
30 #                 this file.  If not, you can view it at
31 #                 http://www.gnu.org/copyleft/gpl.html
32 #                 or write to the Free Software Foundation, Inc., 59
33 #                 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
34 #
35 # Developer's NOTE: This script should be tested against a true /bin/sh, which
36 # has notable differences from bash. By design, this script does not try to do
37 # too much, so as to be as cross-platform as possible.
38 #
39
40 #  Revisions   :
41 #     $Log: privoxy-generic.init,v $
42 #     Revision 1.1  2002/09/06 00:20:26  hal9
43 #     Creating a generic init script, meant to be used on platforms where don't have
44 #     a custom init script.
45 #
46 #     Revision 1.0  2002/09/05 17:14:32  hal9
47 #
48 #######################################################################
49
50 # Is this needed by Solaris?
51 #ident  "@(#)privoxy  1.0     02/09/05"
52
53 # NOTE: This script may require editing to ensure proper location of 
54 # config file, and the privoxy executable. Care should be taken to ensure 
55 # logfile is writable by $P_USER (logfile is defined in config), and that 
56 # there is suitable write access for $P_PIDFILE.
57
58 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin/:/usr/bin:/sbin:/bin
59 P_NAME=Privoxy
60 # Path to executable.
61 P_DAEMON=privoxy
62 P_USER=privoxy
63 # Full path to location of Privoxy config file. 
64 P_CONF_FILE=./config
65 # Full path to PID file location. Location must be writable by 
66 # whoever runs this script.
67 P_PIDFILE=`pwd`/${P_USER}.pid
68 # User that will own the Privoxy process.
69 P_DAEMON_OWNER="$USER"
70
71 if [ ! -f $P_CONF_FILE ]; then
72   echo "Can't find $P_CONF_FILE, exiting."
73   exit 1
74 fi
75
76 # If a privoxy user exists, lets use that. /bin/sh does not seem to 
77 # know about $UID.
78 if [ "$USER" = "root" ] && [ "$P_DAEMON_OWNER" = "$USER" ] && id $P_USER >/dev/null; then
79   P_DAEMON_OWNER="$P_USER"
80 fi
81
82 case "$1" in
83  
84  start)
85      test -f $P_PIDFILE && echo "$P_PIDFILE exists, exiting." && exit 1
86         $P_DAEMON --pidfile $P_PIDFILE --user $P_DAEMON_OWNER $P_CONF_FILE 2>/dev/null &&\
87      echo "Starting $P_NAME, OK." || echo "Starting $P_NAME, Failed."
88         
89      ;;
90  
91  restart)
92      $0 stop
93      $0 start
94      ;;
95  
96  stop)
97      test ! -f $P_PIDFILE && echo "No $P_PIDFILE file found, exiting." && exit 1
98      kill `cat $P_PIDFILE` &&\
99      echo "Stopping $P_NAME, OK." || echo "Stopping $P_NAME, failed."
100      ;;
101  
102  *)
103      echo "Usage: $0 {start|stop|restart}"
104      exit 1
105      ;;
106
107 esac
108
109 exit 0