-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproxy.sh
executable file
·49 lines (40 loc) · 1.21 KB
/
proxy.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
#!/usr/bin/env bash
declare network="${1:-"Wi-Fi"}"
declare -a bypassdomains=(
'*.local'
'169.254/16'
'*.slack-edge.com'
'*.slack.com'
'*.googleapis.com'
'*.mail.google.com'
'*.ssl.gstatic.com'
)
bypass () {
declare hoststr="$(printf "'%s' " "${bypassdomains[@]}")"
networksetup -setproxybypassdomains "${network}" "${hoststr}"
}
setproxy () {
networksetup -setwebproxy "${network}" 127.0.0.1 8080
networksetup -setsecurewebproxy "${network}" 127.0.0.1 8080
}
toggle () {
declare state="$1"
if [[ "$state" == "Yes" ]]; then
networksetup -setsecurewebproxystate "${network}" off
networksetup -setwebproxystate "${network}" off
echo "OFF"
else
bypass
setproxy
networksetup -setsecurewebproxystate "${network}" on
networksetup -setwebproxystate "${network}" on
echo "ON"
fi
}
declare unsecstate="$(networksetup -getwebproxy "$network" | grep -E '^Enabled: (No|Yes)$' | cut -d' ' -f2)"
declare secstate="$(networksetup -getsecurewebproxy "$network" | grep -E '^Enabled: (No|Yes)$' | cut -d' ' -f2)"
if [[ "${secstate}" != "${unsecstate}" ]]; then
networksetup -setsecurewebproxystate "${network}" off
networksetup -setwebproxystate "${network}" off
fi
toggle "${secstate}"