summarylogtreecommitdiffstats
path: root/AdAway.sh
blob: 40fea195781b8ce505766209d0cdd19a8a1b217f (plain)
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
#!/bin/bash
#Var-----------------------------------------------------------
WHITE="\033[1m"
LIGHTRED="\033[1;31m"
RED="\033[31m"
YELLOW="\033[1;33m"
BLUE="\033[34m"
BLUEB="\033[1;34m"
GREEN="\033[32m"
GREENB="\033[1;32m"
ENDCOLOR="\033[0m"
#--------------------------------------------------------------
#Internet Init-------------------------------------------------
echo Starting...
WVER=`wget -h | head -1 | sed 's/[^0-9]*//g'`
DVER=`dialog --version | head -1 | sed 's/-.*//g' | sed 's/[^0-9]*//g'`
if [ "$WVER" -ge 116 ]; then
	if ! [ "$DVER" -ge 12 ]; then
		clear
		echo -e $RED"ERROR: Dialog v1.2 or later is not installed."$ENDCOLOR
		echo
		echo -e $GREEN"Press the ENTER key to exit"$ENDCOLOR
		read
		clear
		exit
	fi
else
	if [ "$DVER" -ge 12 ]; then
		clear
		echo -e $RED"ERROR: Wget v1.16 is not installed."$ENDCOLOR
		echo
		echo -e $GREEN"Press the ENTER key to exit"$ENDCOLOR
		read
		clear
		exit
	else
		clear
		echo -e $RED"ERROR: Wget v1.16 or later is not installed."$ENDCOLOR
		echo -e $RED"ERROR: Dialog v1.2 or later is not installed."$ENDCOLOR
		echo
		echo -e $GREEN"Press the ENTER key to exit"$ENDCOLOR
		read
		clear
		exit
	fi
fi
echo '
#Var-----------------------------------------------------------
WHITE="\033[1m"
LIGHTRED="\033[1;31m"
RED="\033[31m"
YELLOW="\033[1;33m"
BLUE="\033[34m"
BLUEB="\033[1;34m"
GREEN="\033[32m"
GREENB="\033[1;32m"
ENDCOLOR="\033[0m"
#--------------------------------------------------------------
INIT=`wget -q -O /tmp/con.ns --tries=4 --timeout=16 https://bitbucket.org/NjlsShade/adaway/raw/master/init.ns`
CON=`cat /tmp/con.ns`
rm -f /tmp/con.ns
while ! [ $CON == 1 ]
	do
		clear		
		echo "You are$STILL not connected to the Internet."
		$ADDED
		echo If you need to enter a proxy address, type 'proxy' and press enter.
		echo
		echo "Press [ENTER] to try again. Or press Ctrl+C to exit."
		echo
		read PROX
		if [[ $PROX == proxy ]] || [[ $PROX == p ]] || [[ $PROX == PROXY ]] || [[ $PROX == P ]]; then
			clear
			echo -e $RED"This is an experimental feature, make sure the URL and port are correct."$ENDCOLOR
			echo
			echo -e -n $BLUEB"$USER@AdAway [Proxy URL]: "$ENDCOLOR
			read PURL
			if [[ $PURL == *.*.*:* ]]; then
				export http_proxy="$PURL"
				export https_proxy="$PURL"
				export ssl_proxy="$PURL"
				export ftp_proxy="$PURL"
				echo $PURL > /tmp/proxy_ad.txt
			else
				clear
				echo -e $RED"You did not enter a valid URL [XXX.XXX.XXX:XXX]"$ENDCOLOR
				echo
				echo Restarting in [5]
				sleep 1
				clear
				echo -e $RED"You did not enter a valid URL [XXX.XXX.XXX:XXX]"$ENDCOLOR
				echo
				echo Restarting in [4]
				sleep 1
				clear
				echo -e $RED"You did not enter a valid URL [XXX.XXX.XXX:XXX]"$ENDCOLOR
				echo
				echo Restarting in [3]
				sleep 1
				clear
				echo -e $RED"You did not enter a valid URL [XXX.XXX.XXX:XXX]"$ENDCOLOR
				echo
				echo Restarting in [2]
				sleep 1
				clear
				echo -e $RED"You did not enter a valid URL [XXX.XXX.XXX:XXX]"$ENDCOLOR
				echo
				echo Restarting in [1]
				sleep 1
				clear
			fi
		fi
clear
STILL=" still"
ADDED="echo Make sure you are connected to a network with Internet access."
echo -e $GREENB"Please wait..."$ENDCOLOR
INIT=`wget -q -O /tmp/con.ns --tries=8 --timeout=16 https://bitbucket.org/NjlsShade/adaway/raw/master/init.ns`
CON=`cat /tmp/con.ns`
rm -f /tmp/con.ns

done' > /tmp/init.sh
clear
echo -e $GREENB"Please wait..."$ENDCOLOR
chmod +x /tmp/init.sh
bash /tmp/init.sh
rm -f /tmp/init.sh
clear
#Start---------------------------------------------------------
cd ~
clear
echo -e $WHITE"AdAway"$ENDCOLOR
echo
echo -e "Please enter your password"
echo
#Password------------------------------------------------------
cat > /tmp/pass.sh << 'PASS'
#Var-----------------------------------------------------------
WHITE="\033[1m"
LIGHTRED="\033[1;31m"
RED="\033[31m"
YELLOW="\033[1;33m"
BLUE="\033[34m"
GREEN="\033[32m"
ENDCOLOR="\033[0m"
#--------------------------------------------------------------
unset PASSWORD
unset CHARCOUNT

echo -e -n $BLUE"Password: "$ENDCOLOR

stty -echo

CHARCOUNT=0
while IFS= read -p "$PROMPT" -r -s -n 1 CHAR
do
    if [[ $CHAR == $'\0' ]]; then
        break
    fi
    if [[ $CHAR == $'\177' ]]; then
        if [ $CHARCOUNT -gt 0 ]; then
            CHARCOUNT=$((CHARCOUNT-1))
            PROMPT=$'\b \b'
            PASSWORD="${PASSWORD%?}"
        else
            PROMPT=''
        fi
    else
        CHARCOUNT=$((CHARCOUNT+1))
        PROMPT='*'
        PASSWORD+="$CHAR"
    fi
done

stty echo

echo
clear
echo -e $RED"The password given is being checked."$ENDCOLOR
echo -e $RED"Root will be requested with the system prompt if it fails."$ENDCOLOR
echo $PASSWORD | sudo -S clear >/dev/null 2>&1
echo
sudo echo
PASS
chmod +x /tmp/pass.sh
bash /tmp/pass.sh
rm -f /tmp/pass.sh
clear
#Main----------------------------------------------------------
echo -e $GREENB"Please choose an option below"$ENDCOLOR
echo
echo -e $GREEN"[i]         Install AdAway"$ENDCOLOR
echo -e $GREEN"[u]         Uninstall AdAway"$ENDCOLOR
echo -e $GREEN"[e]         Exit"$ENDCOLOR
echo
echo -e -n $BLUEB"$USER@AdAway $ "$ENDCOLOR
read ANS
if [[ $ANS == [iI] ]]; then
	clear
	echo -e $GREENB'Are you sure you want to install AdAway?'$ENDCOLOR
	echo -e $GREEN'(A back up of your hosts file will be made)'$ENDCOLOR
	echo
	echo -e -n $BLUEB"$USER@AdAway $ "$ENDCOLOR
	read ANS
	if [[ $ANS == [Yy] ]] || [ $ANS == 'YES' ] || [ $ANS == 'Yes' ] || [ $ANS == 'yes' ]; then
		INSTL=`cat ~/.adaway/files/version/installed.txt 2> /dev/null`
		if ! [ "$INSTL" == 1 ]; then
			if [ "$INSTL" == 0 ]; then
				clear
				echo -e $GREENB"AdAway was previously removed, but it's configurations were left in tact"$ENDCOLOR
				echo -e $GREEN"Would you like to install AdAway with the existing configurations?"$ENDCOLOR
				echo
				echo -e -n $BLUEB"$USER@AdAway $ "$ENDCOLOR
				read ANS
				if [[ $ANS == [Yy] ]] || [ $ANS == 'YES' ] || [ $ANS == 'Yes' ] || [ $ANS == 'yes' ]; then
					HOSTD=`grep -Po "127.0.1.1 $HOSTNAME" ~/.adaway/backup/hosts`
					if [ "$HOSTD" == "127.0.1.1 $HOSTNAME" ]; then
						sudo cp -f ~/.adaway/backup/hosts /etc/hosts
					fi
					wget -q -O ~/.adaway/tmp/adaway "https://bitbucket.org/NjlsShade/adaway/raw/master/adaway"
					wget -q -O ~/.adaway/tmp/update.ns "https://bitbucket.org/NjlsShade/adaway/raw/master/update.ns"
					sudo mv -f ~/.adaway/tmp/adaway /usr/local/bin
					sudo mv -f ~/.adaway/tmp/update.ns ~/.adaway/files/version/version.ns
					sudo chmod 0755 /usr/local/bin/adaway
					echo "1" > ~/.adaway/files/version/installed.txt
					clear
					echo -e $GREENB"AdAway has been installed successfully!"$ENDCOLOR
					echo -e $GREEN"Press the any key to exit"$ENDCOLOR
					read
					exit
				fi
			fi
			rm -rf ~/.adaway
			mkdir -p ~/.adaway/backup
			mkdir -p ~/.adaway/files/version
			mkdir -p ~/.adaway/files/database
			mkdir -p ~/.adaway/files/hosts
			mkdir -p ~/.adaway/quarantine
			mkdir -p ~/.adaway/tmp
			mkdir -p ~/.adaway/files/proxy
			mkdir -p ~/.adaway/files/config
			touch ~/.adaway/files/database/custom_data.txt
			touch ~/.adaway/files/database/custom_url.txt
			touch ~/.adaway/files/database/servers.txt
			if [ -s /tmp/proxy_ad.txt ]; then
				mv -f /tmp/proxy_ad.txt ~/.adaway/files/proxy/proxy_ad.txt
				PURLI=`cat ~/.adaway/files/proxy/proxy_ad.txt`
				export http_proxy="$PURLI"
				export https_proxy="$PURLI"
				export ssl_proxy="$PURLI"
				export ftp_proxy="$PURLI"
			fi
			echo "0" > ~/.adaway/quarantine/disable.txt
			echo "0" > ~/.adaway/files/database/c_servers.txt
			echo "0" > ~/.adaway/files/database/query_server.txt
#1			echo "0" > ~/.adaway/files/database/server_config.txt
			echo "0.1.0" > ~/.adaway/files/version/script.txt
			echo "1" > ~/.adaway/files/version/installed.txt
			if ! [ -s ~/.dialogrc ]; then
				echo 'aspect = 0
separate_widget = ""
tab_len = 0
visit_items = OFF
use_shadow = OFF
use_colors = OFF
screen_color = (WHITE,DEFAULT,OFF)
shadow_color = (WHITE,WHITE,OFF)
dialog_color = (WHITE,BLACK,OFF)
title_color = (GREEN,BLACK,OFF)
border_color = (WHITE,BLACK,OFF)
button_active_color = (BLACK,YELLOW,OFF)
button_inactive_color = (WHITE,BLACK,OFF)
button_key_active_color = (BLACK,GREEN,OFF)
button_key_inactive_color = (RED,BLACK,OFF)
button_label_active_color = (BLACK,GREEN,OFF)
button_label_inactive_color = (WHITE,BLACK,OFF)
inputbox_color = (WHITE,BLACK,OFF)
inputbox_border_color = (BLACK,BLACK,OFF)
searchbox_color = (WHITE,BLACK,OFF)
searchbox_title_color = (GREEN,BLACK,OFF)
searchbox_border_color = (WHITE,BLACK,OFF)
position_indicator_color = (GREEN,BLACK,OFF)
menubox_color = (BLACK,BLACK,OFF)
menubox_border_color = (BLACK,BLACK,OFF)
item_color = (WHITE,BLACK,OFF)
item_selected_color = (BLACK,GREEN,OFF)
tag_color = (BLUE,BLACK,OFF)
tag_selected_color = (BLACK,GREEN,OFF)
tag_key_color = (YELLOW,BLACK,OFF)
tag_key_selected_color = (BLACK,GREEN,OFF)
check_color = (WHITE,BLACK,OFF)
check_selected_color = (BLACK,GREEN,OFF)
uarrow_color = (GREEN,BLACK,OFF)
darrow_color = (GREEN,BLACK,OFF)
itemhelp_color = (BLACK,WHITE,OFF)
form_active_text_color = (BLACK,BLUE,OFF)
form_text_color = (WHITE,BLACK,OFF)
form_item_readonly_color = (BLACK,WHITE,OFF)' > ~/.dialogrc
				echo "0" > ~/.adaway/files/config/dialogrc.cfg
			else
				echo "1" > ~/.adaway/files/config/dialogrc.cfg
			fi
			sudo cp /etc/hosts ~/.adaway/backup/hosts
			wget -q -O ~/.adaway/tmp/adaway "https://bitbucket.org/NjlsShade/adaway/raw/master/adaway"
			wget -q -O ~/.adaway/tmp/update.ns "https://bitbucket.org/NjlsShade/adaway/raw/master/update.ns"
			sudo mv -f ~/.adaway/tmp/adaway /usr/local/bin
			sudo mv -f ~/.adaway/tmp/update.ns ~/.adaway/files/version/version.ns
			sudo chmod 0755 /usr/local/bin/adaway
			clear
			echo -e $GREENB"AdAway has been installed successfully!"$ENDCOLOR
			echo -e $GREEN"Press the any key to exit"$ENDCOLOR
			read
		else
			TST=`adaway --version | grep -Po "AdAway v" 2> /dev/null`
			if [[ "$TST" == "AdAway v" ]]; then
				clear
				echo -e $GREENB"Adaway is already installed!"$ENDCOLOR
				echo -e $GREEN"Press any key to exit"$ENDCOLOR
				read
				clear
				exit 130
			else
				clear
				echo -e $GREENB"AdAway configuration files have been detected, but, AdAway binary is missing."$ENDCOLOR
				echo -e $GREEN"Would you like to remove the junk fragments of AdAway found on your computer?"$ENDCOLOR
				echo
				echo -e $RED"[THIS WILL REMOVE ALL PRIOR CONFIGURATIONS!]"$ENDCOLOR
				echo -e -n $BLUEB"$USER@AdAway $ "$ENDCOLOR
				read "ANS"
				if [[ "$ANS" == [Yy] ]] || [ $ANS == 'YES' ] || [ $ANS == 'Yes' ] || [ $ANS == 'yes' ]; then
					HOSTD=`grep -Po "127.0.1.1 $HOSTNAME" ~/.adaway/backup/hosts`
					if [ "$HOSTD" == "127.0.1.1 $HOSTNAME" ]; then
						sudo cp -f ~/.adaway/backup/hosts /etc/hosts
					fi
					sudo rm -rf /usr/local/bin/adaway
					DIALOGRC=`cat ~/.adaway/files/config/dialogrc.cfg`
					if [[ DIALOGRC == "0" ]]; then
						sudo rm -rf ~/.dialogrc
					fi
					sudo rm -rf ~/.adaway
					clear
					echo -e $GREENB"Junk configuration files successfully removed!"$ENDCOLOR
					echo -e $GREEN"Press the any key to exit"$ENDCOLOR
					read
					clear
					exit
				else
					clear
					echo -e $RED'Cleaning up, then Exiting installer [4]'$ENDCOLOR
					sleep 1
					clear
					echo -e $RED'Cleaning up, then Exiting installer [3]'$ENDCOLOR
					sleep 1
					clear
					echo -e $RED'Cleaning up, then Exiting installer [2]'$ENDCOLOR
					sleep 1
					clear
					echo -e $RED'Cleaning up, then Exiting installer [1]'$ENDCOLOR
					sleep 1
					clear
				fi
			fi
		fi
	else
		clear
		echo -e $RED'Cleaning up, then Exiting installer [4]'$ENDCOLOR
		sleep 1
		clear
		echo -e $RED'Cleaning up, then Exiting installer [3]'$ENDCOLOR
		sleep 1
		clear
		echo -e $RED'Cleaning up, then Exiting installer [2]'$ENDCOLOR
		sleep 1
		clear
		echo -e $RED'Cleaning up, then Exiting installer [1]'$ENDCOLOR
		sleep 1
		clear
		exit
	fi
fi
if [[ "$ANS" == [Uu] ]]; then
	clear
	echo -e $GREENB"Are you sure you want to completely uninstall AdAway?"$ENDCOLOR
	echo -e $RED"[This will remove AdAway and all configurations!]"$ENDCOLOR
	echo
	echo -e -n $BLUEB"$USER@AdAway $ "$ENDCOLOR
	read ANS
	if [[ $ANS == [Yy] ]] || [ $ANS == 'YES' ] || [ $ANS == 'Yes' ] || [ $ANS == 'yes' ]; then
		INSTL=`cat ~/.adaway/files/version/installed.txt 2> /dev/null`
		if ! [ "$INSTL" == 1 ]; then
			if [ "$INSTL" == 0 ]; then
				clear
				echo -e $GREENB"AdAway was previously removed, but it's configurations were left in tact"$ENDCOLOR
				echo -e $GREEN"Would you still like to uninstall AdAway?"$ENDCOLOR
				echo
				echo -e $RED"[THIS WILL REMOVE ALL CONFIGURATIONS!]"$ENDCOLOR
				echo -e -n $BLUEB"$USER@AdAway $ "$ENDCOLOR
				read "ANS"
				if [[ "$ANS" == [Yy] ]] || [ $ANS == 'YES' ] || [ $ANS == 'Yes' ] || [ $ANS == 'yes' ]; then
					HOSTD=`grep -Po "127.0.1.1 $HOSTNAME" ~/.adaway/backup/hosts`
					if [ "$HOSTD" == "127.0.1.1 $HOSTNAME" ]; then
						sudo cp -f ~/.adaway/backup/hosts /etc/hosts
					fi
					sudo rm -rf /usr/local/bin/adaway
					DIALOGRC=`cat ~/.adaway/files/config/dialogrc.cfg`
					if [[ DIALOGRC == "0" ]]; then
						sudo rm -rf ~/.dialogrc
					fi
					sudo rm -rf ~/.adaway
					clear
					echo -e $GREENB"Junk configuration files successfully removed!"$ENDCOLOR
					echo -e $GREEN"Press the any key to exit"$ENDCOLOR
					read
					clear
					exit
				else
					clear
					echo -e $RED'Cleaning up, then Exiting installer [4]'$ENDCOLOR
					sleep 1
					clear
					echo -e $RED'Cleaning up, then Exiting installer [3]'$ENDCOLOR
					sleep 1
					clear
					echo -e $RED'Cleaning up, then Exiting installer [2]'$ENDCOLOR
					sleep 1
					clear
					echo -e $RED'Cleaning up, then Exiting installer [1]'$ENDCOLOR
					sleep 1
					clear
				fi
			else
				clear
				echo -e $GREENB"AdAway is not installed on your computer!"$ENDCOLOR
				echo -e $GREEN"Press any key to exit"$ENDCOLOR
				read
				clear
				exit
			fi
		else
			TST=`adaway --version | grep -Po "AdAway v" 2> /dev/null`
			if [[ "$TST" == "AdAway v" ]]; then
				sudo cp -f ~/.adaway/backup/hosts /etc/hosts
				sudo rm -rf /usr/local/bin/adaway
				sudo rm -rf ~/.adaway
				clear
				echo -e $GREENB"AdAway has been uninstalled successfully."$ENDCOLOR
				echo -e $GREEN"Press the ENTER key to exit"$ENDCOLOR
				read
				clear
				exit
			else
				clear
				echo -e $GREENB"AdAway configuration files have been detected, but, AdAway binary is missing."$ENDCOLOR
				echo -e $GREEN"Would you like to remove the junk fragments of AdAway found on your computer?"$ENDCOLOR
				echo
				echo -e $RED"[THIS WILL REMOVE ALL PRIOR CONFIGURATIONS!]"$ENDCOLOR
				echo -e -n $BLUEB"$USER@AdAway $ "$ENDCOLOR
				read "ANS"
				if [[ "$ANS" == [Yy] ]] || [ $ANS == 'YES' ] || [ $ANS == 'Yes' ] || [ $ANS == 'yes' ]; then
					HOSTD=`grep -Po "127.0.1.1 $HOSTNAME" ~/.adaway/backup/hosts`
					if [ "$HOSTD" == "127.0.1.1 $HOSTNAME" ]; then
						sudo cp -f ~/.adaway/backup/hosts /etc/hosts
					fi
					sudo rm -rf /usr/local/bin/adaway
					DIALOGRC=`cat ~/.adaway/files/config/dialogrc.cfg`
					if [[ DIALOGRC == "0" ]]; then
						sudo rm -rf ~/.dialogrc
					fi
					sudo rm -rf ~/.adaway
					clear
					echo -e $GREENB"Junk configuration files successfully removed!"$ENDCOLOR
					echo -e $GREEN"Press the any key to exit"$ENDCOLOR
					read
					clear
					exit
				else
					clear
					echo -e $RED'Cleaning up, then Exiting installer [4]'$ENDCOLOR
					sleep 1
					clear
					echo -e $RED'Cleaning up, then Exiting installer [3]'$ENDCOLOR
					sleep 1
					clear
					echo -e $RED'Cleaning up, then Exiting installer [2]'$ENDCOLOR
					sleep 1
					clear
					echo -e $RED'Cleaning up, then Exiting installer [1]'$ENDCOLOR
					sleep 1
					clear
				fi
			fi
		fi
	fi
fi
if [[ $ANS == [Ee] ]]; then
	exit
fi