-
Notifications
You must be signed in to change notification settings - Fork 10
/
smart_switcher.sh
executable file
·71 lines (55 loc) · 1.49 KB
/
smart_switcher.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
#! /bin/sh
# usage: set proxy_server automatically, if you set your proxy info in gateway.ini
################################ setup run only at the beginning of script loaded
setup ()
{
# source intl file
source "${SMART_SWITCHER_DIR}"/smart_switcher_intl.sh
# clear env
do_clear
# routine begin
echo "***************smart proxy switcher****************"
print_proxy_server
# check valid gateway
local GATEWAY=
GATEWAY=$(check_valid_gateway)
# work
[ -n "$GATEWAY" ] && install_proxy "$GATEWAY" || uninstall_proxy
# routine end
print_proxy_server
echo "***************************************************"
}
setup
unset -f do_clear
unset -f print_proxy_server
unset -f get_info
unset -f check_valid_gateway
unset -f install_proxy
unset -f uninstall_proxy
unset -f setup
################################################# sm_trigger will run anytime
sm_toggle ()
{
# source intl file
source "${SMART_SWITCHER_DIR}"/smart_switcher_intl.sh
# clear env
do_clear
# routine begin
echo "***************smart proxy switcher****************"
print_proxy_server
# check valid gateway
local GATEWAY=
GATEWAY=$(check_valid_gateway)
# work
[ -n "$http_proxy" ] && uninstall_proxy ||
{ [ -n "$GATEWAY" ] && install_proxy "$GATEWAY" || uninstall_proxy }
# routine end
print_proxy_server
echo "***************************************************"
unset -f do_clear
unset -f print_proxy_server
unset -f get_info
unset -f check_valid_gateway
unset -f install_proxy
unset -f uninstall_proxy
}