This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproxy
executable file
·118 lines (107 loc) · 4.07 KB
/
proxy
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
115
116
117
118
#!/bin/bash
# function define
setProxy() {
sudo networksetup -setsocksfirewallproxy 'Wi-Fi' 127.0.0.1 9091 &>/dev/null
sudo networksetup -setsecurewebproxystate 'Wi-Fi' off &>/dev/null
sudo networksetup -setwebproxystate 'Wi-Fi' off &>/dev/null
sudo networksetup -setproxybypassdomains 'Wi-Fi' 'localhost, 127.0.0.1' &>/dev/null
sudo networksetup -setsocksfirewallproxy 'iPhone USB' 127.0.0.1 9091 &>/dev/null
sudo networksetup -setsecurewebproxystate 'iPhone USB' off &>/dev/null
sudo networksetup -setwebproxystate 'iPhone USB' off &>/dev/null
sudo networksetup -setproxybypassdomains 'iPhone USB' 'localhost, 127.0.0.1' &>/dev/null
sudo networksetup -setsocksfirewallproxy 'Thunderbolt Ethernet' 127.0.0.1 9091 &>/dev/null
sudo networksetup -setsecurewebproxystate 'Thunderbolt Ethernet' off &>/dev/null
sudo networksetup -setwebproxystate 'Thunderbolt Ethernet' off &>/dev/null
sudo networksetup -setproxybypassdomains 'Thunderbolt Ethernet' 'localhost, 127.0.0.1' &>/dev/null
sudo networksetup -setsocksfirewallproxy 'Ethernet' 127.0.0.1 9091 &>/dev/null
sudo networksetup -setsecurewebproxystate 'Ethernet' off &>/dev/null
sudo networksetup -setwebproxystate 'Ethernet' off &>/dev/null
sudo networksetup -setproxybypassdomains 'Ethernet' 'localhost, 127.0.0.1' &>/dev/null
}
unsetProxy() {
sudo networksetup -setsecurewebproxystate Wi-Fi off &>/dev/null
sudo networksetup -setwebproxystate Wi-Fi off &>/dev/null
sudo networksetup -setsocksfirewallproxystate Wi-Fi off &>/dev/null
sudo networksetup -setsecurewebproxystate 'iPhone USB' off &>/dev/null
sudo networksetup -setwebproxystate 'iPhone USB' off &>/dev/null
sudo networksetup -setsocksfirewallproxystate 'iPhone USB' off &>/dev/null
sudo networksetup -setsecurewebproxystate 'Thunderbolt Ethernet' off &>/dev/null
sudo networksetup -setwebproxystate 'Thunderbolt Ethernet' off &>/dev/null
sudo networksetup -setsocksfirewallproxystate 'Thunderbolt Ethernet' off &>/dev/null
sudo networksetup -setsecurewebproxystate 'Ethernet' off &>/dev/null
sudo networksetup -setwebproxystate 'Ethernet' off &>/dev/null
sudo networksetup -setsocksfirewallproxystate 'Ethernet' off &>/dev/null
}
testProxy() {
curl -s -m 5 www.google.com &>/dev/null
if [[ $? -eq 0 ]]; then
echo "proxy is ready..."
return 0
else
echo "proxy is not ready..."
return 1
fi
}
initProxy(){
# homebrew
brew -v &>/dev/null
if [[ ! $? -eq 0 ]]; then
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
#v2ray-core
type v2ray &>/dev/null
if [[ ! $? -eq 0 ]]; then
brew tap v2ray/v2ray && brew install v2ray-core
else
brew upgrade v2ray-core
fi
cp /usr/local/etc/v2ray/config.json /usr/local/etc/v2ray/config.json.bak
cat ~/.proxy/config.json > /usr/local/etc/v2ray/config.json
}
# main code
case $1 in
init)
initProxy
;;
start)
echo proxy starting and will autostart when reboot...
brew services start v2ray-core
setProxy
;;
stop)
echo proxy stopping and will not autostart when reboot...
brew services stop v2ray-core
unsetProxy
;;
restart)
echo proxy restarting...
unsetProxy
setProxy
cp /usr/local/etc/v2ray/config.json /usr/local/etc/v2ray/config.json.bak
cat ~/.proxy/config.json > /usr/local/etc/v2ray/config.json
brew services restart v2ray-core
;;
status)
echo checking proxy status...
testProxy
brew services list | grep v2ray-core
;;
upgrade)
echo upgrading...
cd ~/.proxy && git stash push && git pull origin develop && git stash pop
cp /usr/local/etc/v2ray/config.json /usr/local/etc/v2ray/config.json.bak
cat ~/.proxy/config.json > /usr/local/etc/v2ray/config.json
proxy restart
cd -
;;
help|*)
echo -e '''
init Download and setup dependencies.
start Start your proxy and setup global proxy environment.
stop Stop your proxy and restore global proxy environment.
restart Restart proxy server (v2ray-core) .
status Show proxy status.
upgrade Upgrade proxy config and current repository, and then restart proxy.
'''
;;
esac