ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/scripts/pvxctl.sh
Revision: 24
Committed: Tue Jul 26 21:46:39 2011 UTC (9 years, 1 month ago) by gpertea
File size: 1810 byte(s)
Log Message:
Line File contents
1 #!/bin/sh
2 # Manages privoxy daemon, allows switching between different configs if
3 # setup right. Either use the -k option to kill any running privoxy, or
4 # supply the name of a privoxy config file name under PRIVOXYRC to start
5 # privoxy with.
6
7 # where actions, templates, etc. are stored
8 # need to chdir into here so paths work properly
9 PRIVOXYCONF=$HOME/ann/misc/cfg/privoxy
10
11 # where config files are stored. these need to
12 # reference PRIVOXYCONF directory properly
13 PRIVOXYRC=$PRIVOXYCONF
14 DEFAULTCFG=config
15 # where to find privoxy application
16 PRIVOXY=$HOME/ann/misc/privoxy
17
18 RETURN=0
19
20 # sanity checks
21 if [ ! -x $PRIVOXY ]; then
22 echo "error: no executable program: $PRIVOXY"
23 exit 1
24 fi
25
26 if [ ! -e $PRIVOXYCONF ]; then
27 echo "error: no such directory: $PRIVOXYCONF"
28 exit 1
29 fi
30 if [ ! -d $PRIVOXYCONF ]; then
31 echo "error: not a directory: $PRIVOXYCONF"
32 exit 1
33 fi
34
35 #if [ -z "$1" ]; then
36 for opt in "-h" "-help" "--h" "--help"; do
37 if [ "x"$opt = "x"$1 ]; then
38 echo "usage: `basename $0` [-k] configname"
39 exit 1
40 fi
41 done
42 # routine to find, kill privoxy
43 killit () {
44 ps xwwo pid,command | while read pid command; do
45 if echo $command | grep -- "$PRIVOXY" >/dev/null; then
46 for signal in "TERM" "INT" "HUP" "KILL"; do
47 kill -$signal $pid
48 RETURN=$?
49 if [ $RETURN -eq 0 ]; then
50 break
51 fi
52 echo "failed: kill $signal $pid" >&2
53 sleep 1
54 done
55 fi
56 done
57 }
58
59 OPT=
60 while getopts "k" OPT; do
61 case $OPT in
62 k)
63 killit
64 exit $RETURN
65 ;;
66 esac
67 done
68 shift $(($OPTIND - 1))
69
70 MODE=$1
71 shift
72
73 if [ -z "$MODE" ]; then
74 MODE=$DEFAULTCFG
75 fi
76
77 if [ ! -s $PRIVOXYRC/$MODE ]; then
78 echo "Error: config file not found ($PRIVOXYRC/$MODE)"
79 exit 1
80 fi
81 killit
82 cd $PRIVOXYRC
83 #exec $PRIVOXY --no-daemon $MODE
84 $PRIVOXY --no-daemon $MODE

Properties

Name Value
svn:executable *