-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
start.sh
executable file
·58 lines (43 loc) · 1.54 KB
/
start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# Source our persisted env variables from container startup
. /etc/transmission/environment-variables.sh
source /etc/openvpn/utils.sh
set_port()
{
re='^[0-9]+$'
if ! [[ $1 =~ $re ]] ; then
echo "Privoxy: ERROR. Supplied port $1 is not a number" >&2; exit 1
fi
# Port: Specify the port which privoxy will listen on. Please note
# that should you choose to run on a port lower than 1024 you will need
# to start privoxy using root.
if test "$1" -lt 1024
then
echo "privoxy: $1 is lower than 1024. Ports below 1024 are not permitted.";
exit 1
fi
echo "Privoxy: Setting port to $1";
# Set the port for the IPv4 interface
adr=$(ip -4 a show eth0| grep -oP "(?<=inet )([^/]+)")
adr=${adr:-"0.0.0.0"}
sed -i -E "s/^listen-address\s+.*/listen-address ${adr}:$1/" "$2"
# Remove the listen-address for IPv6 for now. IPv6 compatibility should come later
sed -i -E "s/^listen-address\s+\[\:\:1.*//" "$2"
}
if [[ "${WEBPROXY_ENABLED}" = "true" ]]; then
echo "Privoxy: Starting"
PROXY_CONF=/etc/privoxy/config
echo "Privoxy: Using config file at $PROXY_CONF"
set_port "${WEBPROXY_PORT}" "${PROXY_CONF}"
/usr/sbin/privoxy --pidfile /opt/privoxy/pidfile ${PROXY_CONF}
sleep 1 # Give it one sec to start up, or at least create the pidfile
if [[ -f /opt/privoxy/pidfile ]]; then
privoxy_pid=$(cat /opt/privoxy/pidfile)
echo "Privoxy: Running as PID $privoxy_pid"
else
echo "Privoxy: ERROR. Did not start correctly, outputting logs"
echo
cat /var/log/privoxy/logfile
echo
fi
fi