-
Notifications
You must be signed in to change notification settings - Fork 1
/
system_proxy_configure.sh
115 lines (96 loc) · 3.41 KB
/
system_proxy_configure.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
## (C) George Goulas, 2011
##
## Proxy service configuration script for OSX
## tested on MacOSX Lion 10.6
##
#set -o errexit
#set -o nounset
#set -o pipefail
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source ${ROOT_DIR}/config.sh
function report {
MSG=$1
if [ -n "${VERBOSE}" ]; then
echo $MSG
fi
}
function enableProxy {
current_url=$(networksetup -getautoproxyurl ${NET_INTERFACE} | grep URL | awk '{print $2}')
if [ "${current_url}" != ${PAC_FILE} ]; then
echo Setautoproxyurl: ${PAC_FILE}, for interface: ${NET_INTERFACE}
networksetup -setautoproxyurl ${NET_INTERFACE} ${PAC_FILE}
fi
current_proxy_port=$(networksetup -getsocksfirewallproxy ${NET_INTERFACE} | grep Port | awk '{print $2}')
if [ "${current_proxy_port}" != "${PORT}" ]; then
echo Setsocksfirewallproxy: localhost ${PORT}, for interface: ${NET_INTERFACE}
networksetup -setsocksfirewallproxy ${NET_INTERFACE} localhost ${PORT}
fi
current_bypass=$(networksetup -getproxybypassdomains ${NET_INTERFACE})
# Change '\n' to ' '
current_bypass=$(echo ${current_bypass})
if [ "${current_bypass}" != "${BYPASS_DOMAINS}" ]; then
echo Setproxybypassdomains: ${BYPASS_DOMAINS}, for interface: ${NET_INTERFACE}
networksetup -setproxybypassdomains ${NET_INTERFACE} ${BYPASS_DOMAINS}
fi
networksetup -getautoproxyurl ${NET_INTERFACE} | grep Enabled | grep Yes > /dev/null
if [ $? -eq 0 ]; then
echo Autoproxy is already on
else
echo Set autoproxystate on
networksetup -setautoproxystate ${NET_INTERFACE} on
fi
networksetup -getsocksfirewallproxy ${NET_INTERFACE} | grep Enabled | grep Yes > /dev/null
if [ $? -eq 0 ]; then
echo Socksfirewallproxy is already on
else
echo Set socksfirewallproxystate on
networksetup -setsocksfirewallproxystate ${NET_INTERFACE} on
fi
}
function disableProxy {
networksetup -getsocksfirewallproxy ${NET_INTERFACE} | grep Enabled | grep Yes > /dev/null
if [ $? -eq 0 ]; then
echo Set socksfirewallproxystate off
networksetup -setsocksfirewallproxystate ${NET_INTERFACE} off
else
echo Socksfirewallproxy is already off
fi
if [ "${OFF_AUTOPROXY}" == "1" ]; then
networksetup -getautoproxyurl ${NET_INTERFACE} | grep Enabled | grep Yes > /dev/null
if [ $? -eq 0 ]; then
echo Set autoproxystate off
networksetup -setautoproxystate ${NET_INTERFACE} off
fi
fi
}
function showStatus {
networksetup -getsocksfirewallproxy ${NET_INTERFACE} | grep Enabled | grep Yes > /dev/null
if [ $? -eq 0 ]; then
echo Socksfirewallproxy for ${NET_INTERFACE}: ON
else
echo Socksfirewallproxy for ${NET_INTERFACE}: OFF
fi
networksetup -getautoproxyurl ${NET_INTERFACE} | grep Enabled | grep Yes > /dev/null
if [ $? -eq 0 ]; then
echo Autoproxy for ${NET_INTERFACE}: ON
else
echo Autoproxy for ${NET_INTERFACE}: OFF
fi
}
opt=${1:-""}
case "${opt}" in
on) report "Enabling Proxy"
enableProxy
;;
off) report "Disabling Proxy"
disableProxy
;;
status) echo status
showStatus
;;
*) echo Options:
echo " on set proxy settings"
echo " off clear proxy settings"
echo " status see proxy settings"
esac