-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwireproxy.sh
54 lines (45 loc) · 1.1 KB
/
wireproxy.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
#!/bin/sh
#
# Perform wireproxy
interval=60
workdir=/wayback
debug="${DEBUG:-}"
if [ "$debug" = "true" ]; then
set -x
workdir=.
fi
config="${workdir}/wg0.conf"
restart() {
pkill wireproxy
# Run wireproxy with silent mode in backgound
wireproxy --daemon --silent --config $config
sleep 3
}
watch() {
endpoint='https://cp.cloudflare.com'
proxy="${PROXY_SERVER}"
code=204
timeout=5
while :; do
if [ -n "${PROXY_SERVER}" ]; then
echo 'Running wireproxy watchdog...'
resp=$(curl -sf --write-out '%{http_code}' --max-time $timeout --proxy "${proxy}" "${endpoint}")
if [ "${resp}" != "${code}" ]; then
echo 'Restarting wireproxy...'
restart
fi
fi
sleep $interval
done
}
main() {
# check dependency
command -v wireproxy > /dev/null || { echo "wireproxy is not installed in this system" 1>&2; exit 0; }
if [ "${debug}" != "true" ]; then
printenv WIREPROXY_CONF > /dev/null || { echo "environment variable WIREPROXY_CONF is not found in this system" 1>&2; exit 0; }
printenv WIREPROXY_CONF > "${config}"
fi
restart
watch
}
main