-
Notifications
You must be signed in to change notification settings - Fork 207
/
setupproxy
executable file
·78 lines (73 loc) · 1.46 KB
/
setupproxy
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
#! /bin/bash -e
# usage
# setupproxy [serviceName] [cmd] <other arguments>
# cmd:
# setHttpAndHttpsProxy
# setHttpProxy
# setHttpsProxy
# setHttpAndHttpsProxyState
# setHttpProxyState
#
#
function setHttpProxy(){
sudo networksetup -setwebproxy $1 $2 $3
}
function setHttpsProxy(){
sudo networksetup -setsecurewebproxy $1 $2 $3
}
function setHttpAndHttpsProxy(){
setHttpProxy $1 $2 $3
setHttpsProxy $1 $2 $3
}
function setHttpProxyState(){
sudo networksetup -setwebproxystate $1 $2
}
function setHttpsProxyState(){
sudo networksetup -setsecurewebproxystate $1 $2
}
function setHttpAndHttpsProxyState(){
setHttpProxyState $1 $2 $3
setHttpsProxyState $1 $2 $3
}
function setAutoProxyState(){
sudo networksetup -setautoproxystate $1 $2
}
function setAutoProxyUrl(){
sudo networksetup -setautoproxyurl $1 $2
}
function onlyATest(){
tmp=`networksetup -getwebproxy Wi-Fi | grep "Enabled.*\([YesNo]\)$"`
#echo "after"
#echo $tmp
enable="on"
if test "$tmp" = "Enabled: No";
then
enable="off"
fi
#echo $enable
sudo networksetup -setautoproxystate $1 $enable
if test $? -gt 0; then
#echo $?
#cause pwd prompt
networksetup -setautoproxystate $1 $enable
fi
}
if [ "$#" -lt "2" ]
then
echo "arguments need more"
exit 1
else
cmd=$1
shift 1;
declare -F ${cmd} > /dev/null
if test $? -eq 0
then
onlyATest $*
${cmd} $*
exit $?
else
echo "no such function ${cmd}"
exit 1
fi
exit 0
fi