-
Notifications
You must be signed in to change notification settings - Fork 3
/
script
executable file
·127 lines (99 loc) · 2.42 KB
/
script
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
119
120
121
122
123
124
125
126
127
#!/bin/sh
APP_NAME="ZeroTierOne"
APP_DIR="/etc/$APP_NAME"
FIREWALL_RULE_FILE="/etc/firewall.d/20-$APP_NAME"
user_echo() { echo "<User-Echo>$@"; }
install() {
mkdir -p $APP_DIR
cp ./$APP_NAME.conf $APP_DIR/$APP_NAME.conf
local arch
arch=$(opkg info libc| grep -F Architecture | awk '{print $2}')
case $arch in
mediatek|ralink|mtmips*)
opkg --add-arch 'mtmips_1004kc:20' install ./mips/libnatpmp*.ipk
opkg --add-arch 'mtmips_1004kc:20' install ./mips/libminiupnpc*.ipk
opkg --add-arch 'mtmips_1004kc:20' install ./mips/zerotier*.ipk
;;
ipq806x)
opkg install ./arm/libnatpmp*.ipk
opkg install ./arm/libminiupnpc*.ipk
opkg install ./arm/zerotier*.ipk
;;
*)
user_echo "Unsupported Architecture: $arch"
return 1
;;
esac
gen_config
/etc/init.d/zerotier enable
start
return 0
}
uninstall() {
stop
/etc/init.d/zerotier enable
rm -rf $APP_DIR
opkg remove zerotier libminiupnpc libnatpmp
rm -f $FIREWALL_RULE_FILE
return 0
}
start() {
/etc/init.d/zerotier start;
read_configs
[ $MODE == 1 ] && /etc/init.d/firewall restart
return 0
}
stop() {
/etc/init.d/zerotier stop;
read_configs
[ $MODE == 1 ] && /etc/init.d/firewall restart
return 0
}
restart() {
stop
start
return 0
}
status() {
local stat
stat="unknown"
local pid=$(pgrep zerotier-one | wc -l)
if [ $pid == '1' ]; then
stat="running"
else
stat="stopped"
fi
echo "{ \"status\" : \"$stat\" }"
return 0
}
reconfigure() {
cp ./$APP_NAME.conf $APP_DIR/$APP_NAME.conf -f
gen_config
return 0
}
read_configs() {
source "$APP_DIR/$APP_NAME.conf"
MODE=$MODE
ID=$ID
}
gen_config(){
read_configs
#generate firewall files
if [ $MODE == 1 ]; then
cat >$FIREWALL_RULE_FILE<<EOF
iface=zt0
iptables -I FORWARD -i \$iface -j ACCEPT
iptables -I FORWARD -o \$iface -j ACCEPT
iptables -t nat -I POSTROUTING -o \$iface -j MASQUERADE
EOF
chmod +x $FIREWALL_RULE_FILE
else
rm -f $FIREWALL_RULE_FILE
fi
/etc/init.d/firewall restart
#set zerotier
uci -q set zerotier.sample_config.enabled='1'
uci -q del zerotier.sample_config.join
uci -q add_list zerotier.sample_config.join=$ID
uci -q commit zerotier
}