forked from Kyrie1965/unblock_keenetic
-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure_keenetic.sh
307 lines (258 loc) · 9.53 KB
/
configure_keenetic.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#!/opt/bin/env bash
if [[ "$DEBUG" -eq '1' ]]; then
set -x
fi
# 8/16 Color vraibles:
TXT_GRN='\e[0;32m'
TXT_RED='\e[0;31m'
TXT_YLW='\e[0;33m'
TXT_BLUE='\e[0;34m'
TXT_RST='\e[0m'
WGET='/opt/bin/wget -q --no-check-certificate'
github_link='https://raw.githubusercontent.com/TeroBlaZe/unblock_keenetic/master'
lanip=$(ndmq -p 'show interface Bridge0' -P address)
### Functions for output formatted text
function echo_OK()
{
echo -e " ${TXT_GRN}OK${TXT_RST}"
}
function echo_FAIL()
{
echo -e " ${TXT_RED}FAIL${TXT_RST}"
}
function echo_RESULT()
{
local result=$*
if [[ "$result" -eq 0 ]]; then
echo_OK
else
echo_FAIL
return 1
fi
}
function confirm_reboot()
{
# call with a prompt string or use a default
read -r -p "${1:-Do you want to reboot now? [y/N]} " response
case "$response" in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}
function _remove_dnscrypt()
{
/opt/etc/init.d/S09dnscrypt-proxy2 stop
opkg remove --force-depends --force-removal-of-dependent-packages --autoremove dnscrypt-proxy2
rm -f /opt/etc/dnscrypt-proxy.toml
rm -f /opt/etc/dnsmasq.conf
echo -en "$WGET -O /opt/etc/dnsmasq.conf $github_link/dnsmasq.conf... "
$WGET -O /opt/etc/dnsmasq.conf $github_link/dnsmasq.conf
echo_RESULT $?
sed -i "s/192.168.1.1/${lanip}/g" /opt/etc/dnsmasq.conf
rm -f /opt/etc/hosts.dnsmasq
echo -en "$WGET -O /opt/etc/hosts.dnsmasq $github_link/hosts.dnsmasq... "
$WGET -O /opt/etc/hosts.dnsmasq $github_link/hosts.dnsmasq
echo_RESULT $?
echo -en "Starting dnsmasq... "
/opt/etc/init.d/S56dnsmasq restart
echo_RESULT $?
}
function _remove_kmod()
{
echo ''
}
function _remove_base_environment()
{
opkg remove --force-depends --force-removal-of-dependent-packages --autoremove tor tor-geoip bind-dig dnsmasq-full ipset iptables dnscrypt-proxy2
rm -rf /opt/etc/tor
rm -f /opt/etc/ndm/fs.d/100-ipset.sh
rm -f /opt/etc/unblock.txt
rm -f /opt/etc/unblock.dnsmasq
rm -f /opt/bin/unblock_ipset.sh
rm -f /opt/bin/unblock_dnsmasq.sh
rm -f /opt/bin/update_dnsmasq.sh
rm -f /opt/etc/init.d/S99unblock
rm -f /opt/etc/ndm/netfilter.d/100-redirect.sh
rm -f /opt/etc/dnsmasq.conf
rm -f /opt/etc/dnscrypt-proxy.toml
rm -f /opt/etc/cron.d/ipsec
rm -f /opt/etc/dnsmasq.conf
rm -f /opt/etc/hosts.dnsmasq
rm -f /opt/bin/configure_keenetic.sh
ndmq -p 'no opkg dns-override'
ndmq -p 'system configuration save'
confirm_reboot && ndmq -p 'system reboot'
}
function _install_dnscrypt()
{
if [[ ! -f /opt/etc/hosts.dnsmasq ]]; then
echo "Ошибка! Основной метод обхода блокировок не реализован в системе. Запустите configure_keenetic.sh без параметров."
exit 1
fi
opkg update
opkg install dnscrypt-proxy2
echo_RESULT $?
rm -f /opt/etc/dnscrypt-proxy.toml
echo -en "$WGET -O /opt/etc/dnscrypt-proxy.toml $github_link/dnscrypt-proxy.toml ... "
$WGET -O /opt/etc/dnscrypt-proxy.toml $github_link/dnscrypt-proxy.toml
/opt/etc/init.d/S09dnscrypt-proxy2 start
echo_RESULT $?
rm -f /opt/bin/unblock_ipset.sh
echo -en "$WGET -O /opt/bin/unblock_ipset.sh $github_link/unblock_ipset_dnscrypt.sh... "
$WGET -O /opt/bin/unblock_ipset.sh $github_link/unblock_ipset_dnscrypt.sh
echo_RESULT $?
chmod +x /opt/bin/unblock_ipset.sh
rm -f /opt/bin/unblock_dnsmasq.sh
echo -en "$WGET -O /opt/bin/unblock_dnsmasq.sh $github_link/unblock_dnsmasq_dnscrypt.sh... "
$WGET -O /opt/bin/unblock_dnsmasq.sh $github_link/unblock_dnsmasq_dnscrypt.sh
echo_RESULT $?
chmod +x /opt/bin/unblock_dnsmasq.sh
/opt/bin/update_dnsmasq.sh
echo_RESULT $?
}
function _install_dnsmasq()
{
opkg update
opkg install bind-dig dnsmasq-full cron
echo_RESULT $?
rm -f /opt/etc/dnsmasq.conf
echo -en "$WGET -O /opt/etc/dnsmasq.conf $github_link/dnsmasq.conf... "
$WGET -O /opt/etc/dnsmasq.conf $github_link/dnsmasq.conf
echo_RESULT $?
sed -i "s/192.168.1.1/${lanip}/g" /opt/etc/dnsmasq.conf
rm -f /opt/etc/hosts.dnsmasq
echo -en "$WGET -O /opt/etc/hosts.dnsmasq $github_link/hosts.dnsmasq... "
$WGET -O /opt/etc/hosts.dnsmasq $github_link/hosts.dnsmasq
echo_RESULT $?
echo -en "Starting dnsmasq... "
/opt/etc/init.d/S56dnsmasq restart
echo_RESULT $?
ndmq -p 'opkg dns-override'
ndmq -p 'system configuration save'
}
function _install_kmod()
{
echo ''
}
function _install_base_environment()
{
opkg update
opkg install tor tor-geoip bind-dig dnsmasq-full ipset iptables cron
echo_RESULT $?
set_type="hash:net"
ipset create testset $set_type -exist > /dev/null 2>&1
retVal=$?
if [[ "$retVal" -ne 0 ]]; then
set_type="hash:ip"
fi
rm -f /opt/etc/ndm/fs.d/100-ipset.sh
echo -en "$WGET -O /opt/etc/ndm/fs.d/100-ipset.sh $github_link/100-ipset.sh... "
$WGET -O /opt/etc/ndm/fs.d/100-ipset.sh $github_link/100-ipset.sh
echo_RESULT $?
chmod +x /opt/etc/ndm/fs.d/100-ipset.sh
sed -i "s/hash:net/${set_type}/g" /opt/etc/ndm/fs.d/100-ipset.sh
rm -f /opt/etc/tor/torrc
echo -en "$WGET -O /opt/etc/tor/torrc $github_link/torrc... "
$WGET -O /opt/etc/tor/torrc $github_link/torrc
echo_RESULT $?
sed -i "s/192.168.1.1/${lanip}/g" /opt/etc/tor/torrc
rm -f /opt/etc/unblock.txt
echo -en "$WGET -O /opt/etc/unblock.txt $github_link/unblock.txt... "
$WGET -O /opt/etc/unblock.txt $github_link/unblock.txt
echo_RESULT $?
rm -f /opt/bin/unblock_ipset.sh
echo -en "$WGET -O /opt/bin/unblock_ipset.sh $github_link/unblock_ipset.sh... "
$WGET -O /opt/bin/unblock_ipset.sh $github_link/unblock_ipset.sh
echo_RESULT $?
chmod +x /opt/bin/unblock_ipset.sh
rm -f /opt/bin/unblock_dnsmasq.sh
echo -en "$WGET -O /opt/bin/unblock_dnsmasq.sh $github_link/unblock_dnsmasq.sh... "
$WGET -O /opt/bin/unblock_dnsmasq.sh $github_link/unblock_dnsmasq.sh
echo_RESULT $?
chmod +x /opt/bin/unblock_dnsmasq.sh
/opt/bin/unblock_dnsmasq.sh
echo_RESULT $?
rm -f /opt/bin/update_dnsmasq.sh
echo -en "$WGET -O /opt/bin/update_dnsmasq.sh $github_link/update_dnsmasq.sh... "
$WGET -O /opt/bin/update_dnsmasq.sh $github_link/update_dnsmasq.sh
echo_RESULT $?
chmod +x /opt/bin/update_dnsmasq.sh
# rm -f /opt/etc/cron.daily/backup
# echo -en "$WGET -O /opt/etc/cron.daily/backup $github_link/backup... "
# $WGET -O /opt/etc/cron.daily/backup $github_link/backup
# echo_RESULT $?
# chmod 600 /opt/etc/cron.daily/backup
rm -f /opt/etc/init.d/S99unblock
echo -en "$WGET -O /opt/etc/init.d/S99unblock $github_link/S99unblock... "
$WGET -O /opt/etc/init.d/S99unblock $github_link/S99unblock
echo_RESULT $?
chmod +x /opt/etc/init.d/S99unblock
sed -i "s/hash:net/${set_type}/g" /opt/etc/init.d/S99unblock
sed -i "s/192.168.1.1/${lanip}/g" /opt/etc/init.d/S99unblock
rm -f /opt/etc/ndm/netfilter.d/100-redirect.sh
echo -en "$WGET -O /opt/etc/ndm/netfilter.d/100-redirect.sh $github_link/100-redirect.sh... "
$WGET -O /opt/etc/ndm/netfilter.d/100-redirect.sh $github_link/100-redirect.sh
echo_RESULT $?
chmod +x /opt/etc/ndm/netfilter.d/100-redirect.sh
sed -i "s/hash:net/${set_type}/g" /opt/etc/ndm/netfilter.d/100-redirect.sh
sed -i "s/192.168.1.1/${lanip}/g" /opt/etc/ndm/netfilter.d/100-redirect.sh
rm -f /opt/etc/dnsmasq.conf
echo -en "$WGET -O /opt/etc/dnsmasq.conf $github_link/dnsmasq.conf... "
$WGET -O /opt/etc/dnsmasq.conf $github_link/dnsmasq.conf
echo_RESULT $?
sed -i "s/192.168.1.1/${lanip}/g" /opt/etc/dnsmasq.conf
rm -f /opt/etc/hosts.dnsmasq
echo -en "$WGET -O /opt/etc/hosts.dnsmasq $github_link/hosts.dnsmasq... "
$WGET -O /opt/etc/hosts.dnsmasq $github_link/hosts.dnsmasq
echo_RESULT $?
if [[ ! -d '/opt/etc/cron.d' ]]; then
mkdir -p /opt/etc/cron.d
fi
echo -e "00 06 * * * root /opt/bin/unblock_ipset.sh\n" > /opt/etc/cron.d/ipsec
chmod 600 /opt/etc/cron.d/ipsec
echo -e '#!/opt/bin/sh\n\nndmq -p "system reboot"' > /opt/etc/ndm/button.d/reboot.sh
chmod +x /opt/etc/ndm/button.d/reboot.sh
ndmq -p 'opkg dns-override'
ndmq -p 'system configuration save'
confirm_reboot && ndmq -p 'system reboot'
sleep 5
}
case "$1" in
remove)
case "$2" in
dnscrypt)
_remove_dnscrypt
;;
kmod)
_remove_kmod
;;
*)
_remove_base_environment
;;
esac
;;
install)
case "$2" in
dnscrypt)
_install_dnscrypt
;;
dnsmasq)
_install_dnsmasq
;;
kmod)
_install_kmod
;;
*)
_install_base_environment
;;
esac
;;
esac
if [[ "$DEBUG" -eq '1' ]]; then
set +x
fi
exit 0