1 |
#!/bin/tcsh -f |
2 |
# Manages privoxy daemon, allows switching between different configs if |
3 |
# setup right. |
4 |
|
5 |
set usage="Usage:\npvxctl {start|stop} [<config>]" |
6 |
|
7 |
# where actions, templates, etc. are stored |
8 |
# need to chdir into here so paths work properly |
9 |
set PRIVOXYCONF=$HOME/ann/misc/cfg/privoxy |
10 |
|
11 |
# where config files are stored. these need to |
12 |
# reference PRIVOXYCONF directory properly |
13 |
set PRIVOXYRC=$PRIVOXYCONF |
14 |
set DEFAULTCFG=config |
15 |
# where to find privoxy application |
16 |
set PRIVOXY=$HOME/ann/misc/privoxy |
17 |
|
18 |
# sanity checks |
19 |
if (! -x $PRIVOXY) then |
20 |
echo "Error: no executable program: $PRIVOXY" |
21 |
exit 1 |
22 |
endif |
23 |
|
24 |
if (! -d $PRIVOXYCONF) then |
25 |
echo "Error: no such directory: $PRIVOXYCONF" |
26 |
exit 1 |
27 |
endif |
28 |
set opt=$1 |
29 |
set MODE=$2 |
30 |
|
31 |
if ("x"$opt == "x") then |
32 |
echo "$usage" |
33 |
exit 1 |
34 |
endif |
35 |
|
36 |
if ($opt =~ /-h/) then |
37 |
echo "$usage" |
38 |
exit 1 |
39 |
endif |
40 |
# routine to find, kill privoxy |
41 |
#if ($opt == "stop") then |
42 |
foreach ps ( `pgrep -l -f "$PRIVOXY" | tr ' \t' '~~'` ) |
43 |
set psline=$ps:s/~/ / |
44 |
set psline=`echo $psline:q` |
45 |
set pid=$psline[1] |
46 |
# echo "pid is $psline[1]" |
47 |
set cmdline=`echo $psline[2] | tr '~' ' '` |
48 |
echo "killing pid $pid ($cmdline)" |
49 |
kill $pid |
50 |
end |
51 |
#endif |
52 |
if ($opt != "start") exit 0 |
53 |
|
54 |
if ("x"$MODE == "x")then |
55 |
set MODE=$DEFAULTCFG |
56 |
endif |
57 |
|
58 |
if (! -s $PRIVOXYRC/$MODE) then |
59 |
echo "Error: config file not found ($PRIVOXYRC/$MODE)" |
60 |
exit 1 |
61 |
endif |
62 |
|
63 |
cd $PRIVOXYRC |
64 |
exec $PRIVOXY --no-daemon $MODE |