-
Notifications
You must be signed in to change notification settings - Fork 18
/
update-torbrowser
executable file
·1346 lines (1138 loc) · 47.6 KB
/
update-torbrowser
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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
## This file is part of Whonix.
## Copyright (C) 2012 - 2014 Patrick Schleizer <adrelanos@riseup.net>
## See the file COPYING for copying conditions.
#set -x
set -o pipefail
set -o errtrace
SCRIPTNAME="$(basename "$BASH_SOURCE")"
IDENTIFIER="torbrowser"
nice_name="Tor Browser"
ICON="/usr/share/icons/anon-icon-pack/tbupdate.ico"
## Developer comment on this script:
## I would be very happy if this script would not be required.
## Unfortunately, it is required. It works around a lot bugs:
## - There is no deb/rpm/whatever package with Tor Browser.
## https://trac.torproject.org/projects/tor/ticket/5236
## https://trac.torproject.org/projects/tor/ticket/3994
## - There is no way to keep Tor Browser updated.
## (Thandy doesn't exist yet.)
## - There is no way to add the Documentation page well visible to Tor Browser:
## https://trac.torproject.org/projects/tor/ticket/6025
## https://trac.torproject.org/projects/tor/ticket/6053
## - Tor Browsers support for Isolating and Transparent Proxies is very limited:
## https://trac.torproject.org/projects/tor/ticket/5611
## - tbb-scripts
## https://github.com/adrelanos/tbb-scripts
tb_error_handler() {
local exit_code="$?"
local MSG="<p>###########################################################
<br></br>## $SCRIPTNAME script bug.
<br></br>## No panic. Nothing is broken. Just some rare condition
<br></br>## has been hit. Try again later. There is likely a
<br></br>## solution for this problem. Please see the Whonix News,
<br></br>## Whonix User Help Forum and Whonix Documentation.
<br></br>## <a href=https://www.whonix.org/wiki/Tor_Browser>https://www.whonix.org/wiki/Tor_Browser</a>
<br></br>## Please report this bug!
<br></br>##
<br></br>## BASH_COMMAND: $BASH_COMMAND
<br></br>## exit_code: $exit_code
<br></br>##
<br></br>## output: $output
<br></br>## output_opts: ${output_opts[@]}
<br></br>## progressbaridx: $progressbaridx
<br></br>##
<br></br>## Experts only:
<br></br>## bash -x $SCRIPTNAME
<br></br>###########################################################</p>"
mkdir --parents ~/".tb"
echo "$MSG" >> ~/".tb/torbrowser_updater_error.log"
if [ "$progressbaridx" = "" ]; then
true
else
$output ${output_opts[@]} --progressbaridx "$progressbaridx" --progressx "100" || true
progressbaridx=""
fi
$output ${output_opts[@]} --messagex --typex "error" --message "$MSG" --done
$output ${output_opts[@]} --messagecli --typecli "error" --message "$MSG" --done
exit 1
}
trap "tb_error_handler" ERR
DOWNLOAD_FAIL_HELP="<p>Possible reasons:</p>
<p>
<br></br>- The download server is down.
<br></br>- File size exceeded (endless data attack triggered).
<br></br>- Tor Browser Updater (by Whonix developers) has been broken due to upstream changes.
</p>
<p>Recommendations:</p>
<p>
<br></br>- Try again later. If the error persists it probably won't solve itself before the next update.
<br></br>- Check News: <a href=https://www.whonix.org/wiki/Download#Stay_tuned>https://www.whonix.org/wiki/Download#Stay_tuned</a>
<br></br>- Manually update: <a href=https://www.whonix.org/wiki/Manually_Updating_Tor_Browser>https://www.whonix.org/wiki/Manually_Updating_Tor_Browser</a>
</p>"
tb_run_function() {
case $tb_skip_functions in
*"${1+"$@"}"*) echo "INFO: Skipping ${1+"$@"}, because tb_skip_functions includes it."
return 0
;;
esac
true "INFO: Running ${1+"$@"}, because tb_skip_functions does not include it."
eval ${1+"$@"}
}
root_check() {
if [ "$(id -u)" != "0" ]; then
#echo "$SCRIPTNAME running as user."
true
else
echo "Do not run $SCRIPTNAME as root!"
exit 1
fi
}
tb_sanity_tests() {
command -v id >/dev/null
command -v basename >/dev/null
command -v touch >/dev/null
command -v uname >/dev/null
command -v mkdir >/dev/null
command -v pidof >/dev/null
command -v chmod >/dev/null
command -v cp >/dev/null
command -v mv >/dev/null
command -v killall >/dev/null
command -v rm >/dev/null
command -v head >/dev/null
command -v tar >/dev/null
command -v date >/dev/null
command -v /usr/lib/msgcollector/msgcollector >/dev/null
## tbbversion function
command -v grep >/dev/null
## tbbversion function
command -v sed >/dev/null
command -v sort >/dev/null
}
tb_ex_funct() {
local MSG
MSG="$SIGNAL_TYPE received. Cleaning up..."
if [ "$last_pid" = "" ]; then
true
else
kill -1 "$last_pid"
fi
if [ "$progressbaridx" = "" ]; then
true
else
$output ${output_opts[@]} --progressbaridx "$progressbaridx" --progressx "100" || true
progressbaridx=""
fi
$output ${output_opts[@]} --messagecli --typecli "info" --message "$MSG" --done
#MSG="Aborted."
#$output ${output_opts[@]} --messagex --typex "error" --message "$MSG" --done
#$output ${output_opts[@]} --messagecli --typecli "error" --message "$MSG" --done
MSG="$SIGNAL_TYPE received. Exiting."
$output ${output_opts[@]} --messagecli --typecli "info" --message "$MSG" --done
}
tb_signal_sigterm() {
SIGNAL_TYPE="sigterm"
tb_ex_funct
exit 143
}
trap "tb_signal_sigterm" SIGTERM
tb_signal_sigint() {
SIGNAL_TYPE="sigint"
tb_ex_funct
exit 130
}
trap "tb_signal_sigint" SIGINT ## ctrl + c
trap_sigusr2() {
SIGNAL_TYPE="SIGUSR2"
tb_ex_funct
exit 0
}
trap "trap_sigusr2" SIGUSR2 ## msgcollector, zenity cancel button
tb_parse_cmd_options() {
## Thanks to:
## http://mywiki.wooledge.org/BashFAQ/035
while :
do
case $1 in
--ordinary)
ORDINARY_PROGRESS_BAR="1"
shift
;;
--update)
TB_UPDATE="1"
shift
;;
--noask)
TB_UPDATE="1"
TB_FORCE_INSTALL="1"
shift
;;
--nokilltb)
TB_UPDATE="1"
NOKILLTB="1"
shift
;;
--devbuildpassthrough)
TB_UPDATE="1"
TB_FORCE_INSTALL="1"
DEV_BUILD_PASSTHROUGH="1"
DEV_PASSTHROUGH="1"
ORDINARY_PROGRESS_BAR="1"
shift
;;
## Keeping --clearnet this for compatibility. Does nothing anymore,
## because --clearnet is now the default.
--clearnet)
TB_CLEARNET="1"
shift
;;
--noaskstart)
noaskstart="true"
shift
;;
--language)
TB_LANG="$2"
shift 2
;;
--no-tor-con-check)
TB_NO_TOR_CON_CHECK="1"
shift 1
;;
--alpha)
TB_VERSIONS_ALPHA="1"
shift 1
;;
--beta)
TB_VERSIONS_BETA="1"
shift 1
;;
--rc)
TB_VERSIONS_RC="1"
shift 1
;;
--)
shift
break
;;
-*)
echo "$SCRIPTNAME unknown option: $1"
echo "See:"
echo " man $SCRIPTNAME"
exit 1
;;
*)
break
;;
esac
done
## If there are input files (for example) that follow the options, they
## will remain in the "$@" positional parameters.
true "$BASH_SOURCE \$@: $@"
}
outputfunc() {
if [ "$outputfunc_verbose" = "true" ]; then
echo "Running: bash -x $output_tool --identifier $IDENTIFIER --whoami $who_ami ${1+$@}"
bash -x $output_tool --identifier "$IDENTIFIER" --whoami "$who_ami" ${1+"$@"}
else
$output_tool --identifier "$IDENTIFIER" --whoami "$who_ami" ${1+"$@"}
fi
true
}
## Make it visible to curl-prgrs.
export -f outputfunc
tb_config_folder_parser() {
for i in /etc/torbrowser.d/*; do
if [ -f "$i" ]; then
## If the last character is a ~, ignore that file,
## because it was created by some editor,
## which creates backup files.
if [ "${i: -1}" = "~" ]; then
continue
fi
## Skipping files such as .dpkg-old and .dpkg-dist.
if ( echo "$i" | grep -q ".dpkg-" ); then
true "skip $i"
continue
fi
bash -n "$i"
source "$i"
fi
done
}
tb_preparation() {
## Workaround for CI compatibility.
if [ "$CI" = "true" ]; then
[ -n "$tb_home_folder" ] || tb_home_folder=/home/user
else
[ -n "$tb_home_folder" ] || tb_home_folder=~
fi
## Required for /usr/lib/anon-shared-helper-scripts/tor_bootstrap_check.bsh.
TEMP_DIR="$tb_home_folder/.tb/temp_dir"
export TEMP_DIR
rm --recursive --force "$TEMP_DIR"
mkdir --parents "$TEMP_DIR"
## Fortunately, on linux-image-486 kernel, while "uname --all" returns for example
## "Linux host 3.2.0-4-486 #1 Debian 3.2.41-2 i686 GNU/Linux",
## "uname --machine" returns "i686" and Tor Browser works fine with linux-image-486 kernel.
## (There are no 486 downloads for Tor Browser.)
##ARCH="x86_64"
##ARCH="i686"
[ -n "$ARCH" ] || ARCH="$(uname --machine)"
echo "INFO: $ARCH detected."
if [ "$ARCH" = "i686" ]; then
[ -n "$ARCH_NEW" ] || ARCH_NEW="linux32"
else
## NOTE: A simple else is non-ideal, should there be ever more architectures.
[ -n "$ARCH_NEW" ] || ARCH_NEW="linux64"
fi
echo "INFO: arch $ARCH_NEW will be downloaded."
## provides tbbversion function
source /usr/lib/tbbversion_parser
#echo "INFO: TB_LANG: $TB_LANG"
## Check if TB_LANG exists and is not empty.
if [[ "$TB_LANG" && "${TB_LANG}" ]]; then
#echo "INFO: Tor Browser language variable is set to "$TB_LANG"."
true
else
#echo "INFO: Tor Browser language variable not found. Setting TB_LANG to the default en-US."
TB_LANG="en-US"
fi
if [ "$display" = "" ]; then
if [ "$DISPLAY" = "" ]; then
display=":0"
else
display="$DISPLAY"
fi
fi
if [ "$TB_FORCE_INSTALL" = "1" ]; then
output="true"
else
output="/usr/lib/msgcollector/msgcollector"
fi
local my_tty
local my_tty_exit_code
my_tty_exit_code="0"
my_tty="$(tty)" || { my_tty_exit_code="$?" ; true; };
if [ ! "$my_tty_exit_code" = "0" ]; then
my_tty="none"
fi
## Just in case.
if [ "$my_tty" = "" ]; then
my_tty="none"
fi
who_ami="$(whoami)"
TITLE="Tor Browser Updater (by Whonix developers)"
output_tool="/usr/lib/msgcollector/msgcollector"
output="outputfunc"
$output --icon "$ICON"
$output --parenttty "$my_tty"
$output --whoami "$who_ami"
$output --titlex "$TITLE"
$output --titlecli "$TITLE"
## Make visible to curl-prgrs.
export output_tool
export output
export IDENTIFIER
export who_ami
ret="0"
command -v curl.anondist-orig >/dev/null || { ret="$?" ; true; };
if [ "$ret" = "0" ]; then
## using the non-uwt-wrapped version, if the uwt wrapper is installed,
## which is the case on a default Whonix installation
CURL=curl.anondist-orig
else
ret="0"
command -v curl >/dev/null || { ret="$?" ; true; };
if [ "$ret" = "0" ]; then
## falling back to real curl, if the uwt wrapper has been uninstalled
CURL=curl
else
local MSG="uwt_tool: Can not find curl. Please report this bug!"
$output ${output_opts[@]} --messagex --typex "error" --message "$MSG"
$output ${output_opts[@]} --messagecli --typecli "error" --message "$MSG"
EXIT_CODE="1"
return 0
fi
fi
if [ -x /usr/lib/curl-scripts/curl-prgrs ]; then
## Curl progress wrapper.
CURL_PRGRS="/usr/lib/curl-scripts/curl-prgrs"
else
true "/usr/lib/curl-scripts/curl-prgrs not available, skipping."
true "Setting CURL_PRGRS to $CURL."
CURL_PRGRS="$CURL"
fi
if [ "$ORDINARY_PROGRESS_BAR" = "1" ]; then
true "--ordinary enabled, setting CURL_PRGRS to $CURL."
CURL_PRGRS="$CURL"
fi
## Debugging CURL_PRGRS.
#CURL_PRGRS="bash -x /usr/lib/curl-scripts/curl-prgrs"
## Debugging / disabling CURL_PRGRS.
#CURL_PRGRS="$CURL"
## Export CURL variable, so it can be read by $CURL_PRGRS.
export CURL
mkdir --parents "$tb_home_folder/.tb"
## {{ Download from the torproject.org clearnet by default instead from
## their hidden service.
[ -n "$TBB_REMOTE_FOLDER" ] || TBB_REMOTE_FOLDER="https://dist.torproject.org/torbrowser"
[ -n "$CURL_FORCE_SSL" ] || CURL_FORCE_SSL="--tlsv1 --proto =https"
## }}
if [ "$DEV_PASSTHROUGH" = "1" ]; then
[ -n "$CURL_PROXY" ] || CURL_PROXY=""
elif [ -d /usr/share/whonix ]; then
[ -n "$GATEWAY_IP" ] || GATEWAY_IP="10.152.152.10"
[ -n "$SOCKS_PORT_TBB_DOWNLOAD" ] || SOCKS_PORT_TBB_DOWNLOAD="9115"
[ -n "$CURL_PROXY" ] || CURL_PROXY="--socks5-hostname socks5h://$GATEWAY_IP:$SOCKS_PORT_TBB_DOWNLOAD/"
else
[ -n "$CURL_PROXY" ] || CURL_PROXY=""
fi
## Also used by function tbbversion.
[ -n "$RecommendedTBBVersions" ] || RecommendedTBBVersions="$tb_home_folder/.tb/RecommendedTBBVersions"
}
tb_connectivity_checks_tor() {
if [ "$DEV_BUILD_PASSTHROUGH" = "1" ]; then
return 0
fi
if [ "$TB_NO_TOR_CON_CHECK" = "1" ]; then
return 0
fi
if [ -x /usr/lib/anon-shared-helper-scripts/tor_enabled_check ]; then
echo -n "INFO: Running Tor enabled check... "
source /usr/lib/anon-shared-helper-scripts/tor_enabled_check
## sets: TOR_ENABLED
check_tor_enabled_do
if [ "$TOR_ENABLED" = "0" ]; then
MSG="<p><b>Tor not enabled yet.</b></p>
<p>Please check: <blockquote>Start menu -> System -> Whonix Check
<br></br>or in Terminal: whonixcheck
<br></br>or in Terminal with debugging: whonixcheck -v</blockquote></p>
<p>Run whonixcheck on Whonix-Gateway as well.</p>
<p>If whonixcheck reports no problems with internet activity and this still fails, please report a bug!</p>"
$output ${output_opts[@]} --messagex --typex "error" --message "$MSG" --done
$output ${output_opts[@]} --messagecli --typecli "error" --message "$MSG" --done
exit 1
fi
echo "Done."
else
true "/usr/lib/anon-shared-helper-scripts/tor_enabled_check does not exist, skipping."
fi
if [ -x /usr/lib/anon-shared-helper-scripts/tor_bootstrap_check.bsh ]; then
echo -n "INFO: Running Tor bootstrap check... "
source /usr/lib/anon-shared-helper-scripts/tor_bootstrap_check.bsh
## sets: tor_bootstrap_percent
tb_run_function check_tor_bootstrap_helper
if [ ! "$tor_bootstrap_percent" = "100" ]; then
MSG="<p></b>Tor not fully bootstrapped.</b></p>
<p>Possible reasons:
<br></br>- no internet connectivity</p>
<p>Please check: <blockquote>Start menu -> System -> Whonix Check
<br></br>or in Terminal: whonixcheck
<br></br>or in Terminal with debugging: whonixcheck -v</blockquote></p>
<p>Run whonixcheck on Whonix-Gateway as well.</p>
<p>If whonixcheck reports no problems with internet activity and this still fails, please report a bug!</p>"
$output ${output_opts[@]} --messagex --typex "error" --message "$MSG" --done
$output ${output_opts[@]} --messagecli --typecli "error" --message "$MSG" --done
exit 1
fi
echo "Done."
else
true "/usr/lib/anon-shared-helper-scripts/tor_bootstrap_check.bsh not available, skipping."
fi
true "Tor fully bootstrapped."
}
tb_connectivity_checks_curl() {
if [ "$DEV_BUILD_PASSTHROUGH" = "1" ]; then
return 0
fi
tb_notify_details="Checking connectivity... Will take a moment..."
echo "INFO: Running connectivity check... "
## 1 MB = 1048576 bytes
## 2 MB = 2097152 bytes
## Export CURL_PRGRS_MAX_FILE_SIZE_BYTES, so $CURL_PRGRS can read it.
export CURL_PRGRS_MAX_FILE_SIZE_BYTES="2097152"
## Export CURL_OUT_FILE, so $CURL_PRGRS can read it.
export CURL_OUT_FILE="$tb_home_folder/.tb/tbb_remote_folder"
curl_download_max_time="180"
curl_download_target_url="$TBB_REMOTE_FOLDER"
tb_download_common
## Check if curl failed.
if [ ! "$curl_exit_code" = "0" ]; then
MSG="<p>$curl_download_target_url could not be reached.</p>
<p>Possible reasons:
<br></br>- $TBB_REMOTE_FOLDER is down
<br></br>- download location changed</p>
<p>Please check: <blockquote>Start menu -> System -> Whonix Check
<br></br>or in Terminal: whonixcheck
<br></br>or in Terminal with debugging: whonixcheck -v</blockquote></p>
<p>If whonixcheck reports no problems with internet activity and this keeps failing, please report a bug!</p>
<p>(Debugging information: curl_status_message: $curl_status_message)</p>"
$output ${output_opts[@]} --messagex --typex "error" --message "$MSG" --done
$output ${output_opts[@]} --messagecli --typecli "error" --message "$MSG" --done
exit 1
fi
echo "INFO: Connectivity check succeeded."
}
tb_update_check() {
## do not re-download Tor Browser if a previous build already did
if [ "$DEV_BUILD_PASSTHROUGH" = "1" ]; then
if [ -d "$tb_home_folder/tor-browser_$TB_LANG" ]; then
echo "$SCRIPTNAME: Not downloading Tor Browser again, because $tb_home_folder/tor-browser_$TB_LANG already exists."
exit 0
fi
fi
[ -n "$TBB_VERSIONS_FILE_LINK" ] || TBB_VERSIONS_FILE_LINK="https://www.torproject.org/projects/torbrowser/RecommendedTBBVersions"
tb_notify_details="Checking Tor Browser version... Will take a moment..."
echo "INFO: Find out latest version... Downloading: $TBB_VERSIONS_FILE_LINK... "
## 1 MB = 1048576 bytes
## 2 MB = 2097152 bytes
## Export CURL_PRGRS_MAX_FILE_SIZE_BYTES, so $CURL_PRGRS can read it.
export CURL_PRGRS_MAX_FILE_SIZE_BYTES="2097152"
## Export CURL_OUT_FILE, so $CURL_PRGRS can read it.
export CURL_OUT_FILE="$RecommendedTBBVersions"
curl_download_max_time="180"
curl_download_target_url="$TBB_VERSIONS_FILE_LINK"
tb_download_common
## Check if curl failed.
if [ ! "$curl_exit_code" = "0" ]; then
MSG="<p><b>Failed to download:</b> $curl_download_target_url</p>
<p>$DOWNLOAD_FAIL_HELP</p>
<p>(Debugging information: curl_status_message: $curl_status_message)</p>"
$output ${output_opts[@]} --messagex --typex "error" --message "$MSG" --done
$output ${output_opts[@]} --messagecli --typecli "error" --message "$MSG" --done
exit 1
fi
}
tb_remote_version_parser() {
test -f "$RecommendedTBBVersions"
## needs: $RecommendedTBBVersions
## sets: tbb_recommended_versions_list
## sets: tbbversions_found
## sets: tbb_recommended_versions_error
tb_run_function tbbversion
}
tb_remote_version_sanity_test() {
if [ "$tbb_recommended_versions_list" = "UNKNOWN" ]; then
local MSG="<p>$installed_or_not_text</p>
<p>Could not find out latest Tor Browser version! $tbb_recommended_versions_error</p>
<p>$DOWNLOAD_FAIL_HELP</p>"
$output ${output_opts[@]} --messagex --typex "error" --message "$MSG" --done
$output ${output_opts[@]} --messagecli --typecli "error" --message "$MSG" --done
exit 1
fi
}
tb_local_version_detection() {
## Used by tbbversion_installed
[ -n "$tbb_folder" ] || tbb_folder="$tb_home_folder/tor-browser_$TB_LANG"
## sets: tbb_locally_installed_version
tb_run_function tbbversion_installed
if [ -d "$tb_home_folder/tor-browser_$TB_LANG" ]; then
installed_or_not_result="true"
installed_or_not_text=""
else
installed_or_not_result="false"
installed_or_not_text="Tor Browser is currently not installed.
(Folder $tb_home_folder/tor-browser_$TB_LANG does not exist.)"
fi
}
tb_confirm_update() {
if [ "$installed_or_not_result" = "true" ]; then
local tbb_version
for tbb_version in $tbb_recommended_versions_list; do
local dpkg_compare_versions_equals_exit_code="0"
dpkg --compare-versions "$tbb_version" eq "$tbb_locally_installed_version" || { dpkg_compare_versions_equals_exit_code="$?" ; true; };
if [ "$dpkg_compare_versions_equals_exit_code" = "0" ]; then
break
fi
local dpkg_compare_versions_greater_than_exit_code="0"
dpkg --compare-versions "$tbb_version" gt "$tbb_locally_installed_version" || { dpkg_compare_versions_greater_than_exit_code="$?" ; true; };
if [ "$dpkg_compare_versions_greater_than_exit_code" = "0" ]; then
break
fi
local dpkg_compare_versions_lower_than_exit_code="0"
dpkg --compare-versions "$tbb_version" lt "$tbb_locally_installed_version" || { dpkg_compare_versions_lower_than_exit_code="$?" ; true; };
#if [ "$dpkg_compare_versions_lower_than_exit_code" = "0" ]; then
#break
#fi
done
fi
local MSG question button
button="yesno"
question="Download now?"
if [ "$installed_or_not_result" = "true" ]; then
if [ "$dpkg_compare_versions_equals_exit_code" = "0" ]; then
up_to_date_or_not_text="<p>Looks like Tor Browser is already up to date.</p>"
re_install_or_install_text="<p>Please close Tor Browser if you want to (re-)install!</p>"
elif [ "$dpkg_compare_versions_greater_than_exit_code" = "0" ]; then
up_to_date_or_not_text="<p>Looks like there is an upgrade for Tor Browser.</p>"
re_install_or_install_text="<p>Please close Tor Browser if you want to (re-)install!</p>"
elif [ "$dpkg_compare_versions_lower_than_exit_code" = "0" ]; then
up_to_date_or_not_text="<p><b><u>WARNING: Looks like a downgrade attack!</u></b></p>"
re_install_or_install_text="<p>Please close Tor Browser if you want to (re-)install!</p>"
else
error "<p>Neither of the following were zero.
<br></br>dpkg_compare_versions_equals_exit_code: $dpkg_compare_versions_equals_exit_code
<br></br>dpkg_compare_versions_lower_than_exit_code: $dpkg_compare_versions_lower_than_exit_code
<br></br>dpkg_compare_versions_greater_than_exit_code: $dpkg_compare_versions_greater_than_exit_code</p>"
exit 1
fi
MSG="Download Confirmation
<br></br>----------------------------------------------------------------------
<br></br>Currently installed version: <code><blockquote>$tbb_locally_installed_version</blockquote></code>
Online detected version(s) : <code><blockquote>$tbb_recommended_versions_list</blockquote></code>
$up_to_date_or_not_text
$re_install_or_install_text
<p>If your currently installed version is:
<blockquote>higher: you are likely victim of a downgrade attack, SAY NO NOW!
<br></br>equal : only proceed, if you want to create a new browser profile.
<br></br>lower : you should upgrade.</blockquote></p>
<p>YOUR BROWSER WILL BE KILLED.
<br></br>YOUR WHOLE BROWSER PROFILE INCLUDING BOOKMARKS AND PASSWORDS WILL GET REPLACED!</p>
<p>A backup of your old Tor Browser and settings will be created in your home folder.
<br></br>It is a good idea to delete old TBB backups once in a while if you are running low with disk space.</p>"
else
MSG="Download Confirmation
<br></br>----------------------------------------------------------------------
<br></br>Currently installed version: <code><blockquote>$tbb_locally_installed_version</blockquote></code>
Online detected version(s) : <code><blockquote>$tbb_recommended_versions_list</blockquote></code>"
fi
echo "INFO: Currently installed version: $tbb_locally_installed_version"
echo "INFO: Online detected version(s) : $tbb_recommended_versions_list"
if [ "$TB_FORCE_INSTALL" = "1" ]; then
echo "INFO: TB_FORCE_INSTALL = 1"
else
local answer
answer="$(/usr/lib/msgcollector/generic_gui_message "info" "$TITLE" "$MSG" "$question" "$button")"
if [ ! "$answer" = "16384" ]; then ## Button 'Yes' has not been pressed.
echo "INFO: Canceled. Exit."
exit 0
fi
fi
if [ ! "$NOKILLTB" = "1" ]; then
echo "INFO: Because you are not using --nokilltb, now killing eventually still running instances of Tor Browser..."
killall firefox || true
fi
}
tb_download_common() {
if [ "$TB_FORCE_INSTALL" = "1" ]; then
true
else
progressbaridx="$(cat "/proc/sys/kernel/random/uuid")"
tb_notify_msg="Download
----------------------------------------------------------------------
$tb_notify_details"
$output ${output_opts[@]} --progressbaridx "$progressbaridx" --progressbarx --parentpid "$$" --typex "info" --progressbartitlex "$TITLE" --message "$tb_notify_msg" --parentpid "$$" --done
## $CURL_PRGRS honors the $CURL and the $CURL_PRGRS_EXEC environment
## variables. (See above.)
## Define what CURL_PRGRS is supposed to eval.
## ($percent is a local variable provided by $CURL_PRGRS.)
export CURL_PRGRS_EXEC="$output ${output_opts[@]} --progressbaridx "$progressbaridx" --progressx \"\$percent\""
fi
## Simulating endless data attack.
#export CURL_PRGRS_MAX_FILE_SIZE_BYTES="1048576"
curl_exit_code="0"
$CURL_PRGRS \
--fail \
$CURL_PROXY \
$CURL_FORCE_SSL \
--max-time "$curl_download_max_time" \
--output "$CURL_OUT_FILE" \
"$curl_download_target_url" \
&
last_pid="$!"
wait "$last_pid" || { curl_exit_code="$?" ; true; };
last_pid=""
if [ "$progressbaridx" = "" ]; then
true
else
$output ${output_opts[@]} --progressbaridx "$progressbaridx" --progressx "100" || true
progressbaridx=""
fi
if [ -x "/usr/lib/curl-scripts/curl_exit_codes" ]; then
curl_status_message="$(/usr/lib/curl-scripts/curl_exit_codes "$curl_exit_code")" || true
else
curl_status_message="$curl_exit_code"
fi
## Check if curl failed.
if [ ! "$curl_exit_code" = "0" ]; then
if [ ! "$tb_download_attempt_last_try" = "true" ]; then
MSG="<p><b>Failed to download:</b> $curl_download_target_url
<br></br>There are other recommended versions. Will try to download the next recommended version...</p>
<p>(Debugging information: curl_status_message: $curl_status_message)</p>"
## No popup message in X. Would be too confusing.
#$output ${output_opts[@]} --messagex --typex "info" --message "$MSG" --done
$output ${output_opts[@]} --messagecli --typecli "info" --message "$MSG" --done
else
MSG="<p>Failed to download: $curl_download_target_url</p>
<p>$DOWNLOAD_FAIL_HELP</p>"
$output ${output_opts[@]} --messagex --typex "error" --message "$MSG" --done
$output ${output_opts[@]} --messagecli --typecli "error" --message "$MSG" --done
exit 1
fi
fi
echo "INFO: Done, downloaded $curl_download_target_url."
}
tb_download_files() {
[ -n "$TBB_EXTRA_FOLDER" ] || TBB_EXTRA_FOLDER="${tbb_version_folder}"
### signature ###
[ -n "$TBB_SIG_FILENAME" ] || TBB_SIG_FILENAME="sha256sums.txt.asc"
[ -n "$TBB_SIG_LINK" ] || TBB_SIG_LINK="${TBB_REMOTE_FOLDER}/${TBB_EXTRA_FOLDER}/${TBB_SIG_FILENAME}"
tb_notify_details="Downloading Tor Browser signature... Will take a moment..."
echo "INFO: Downloading GPG signature... Will take a moment..."
echo "\
INFO: Downloading:
$TBB_SIG_LINK ... Will take a moment..."
## 1 MB = 1048576 bytes
## 2 MB = 2097152 bytes
## Export CURL_PRGRS_MAX_FILE_SIZE_BYTES, so $CURL_PRGRS can read it.
export CURL_PRGRS_MAX_FILE_SIZE_BYTES="2097152"
## Export CURL_OUT_FILE, so $CURL_PRGRS can read it.
export CURL_OUT_FILE="$tb_home_folder/.tb/$TBB_SIG_FILENAME"
curl_download_max_time="180"
curl_download_target_url="$TBB_SIG_LINK"
tb_download_common
if [ ! "$curl_exit_code" = "0" ]; then
## Unset those, so during next invocation by tb_download_loop these can
## be set again.
unset TBB_EXTRA_FOLDER
unset TBB_SIG_FILENAME
unset TBB_SIG_LINK
## return 0, so the loop might try the next $tbb_version.
return 0
fi
### hash file ###
[ -n "$TBB_HASH_FILENAME" ] || TBB_HASH_FILENAME="sha256sums.txt"
[ -n "$TBB_HASH_LINK" ] || TBB_HASH_LINK="${TBB_REMOTE_FOLDER}/${TBB_EXTRA_FOLDER}/${TBB_HASH_FILENAME}"
tb_notify_details="Downloading Tor Browser sha256sums file... Will take a moment..."
echo "INFO: Downloading sha256sums file... Will take a moment..."
echo "\
INFO: Downloading:
$TBB_HASH_LINK ... Will take a moment..."
## 1 MB = 1048576 bytes
## 2 MB = 2097152 bytes
## Export CURL_PRGRS_MAX_FILE_SIZE_BYTES, so $CURL_PRGRS can read it.
export CURL_PRGRS_MAX_FILE_SIZE_BYTES="2097152"
## Export CURL_OUT_FILE, so $CURL_PRGRS can read it.
export CURL_OUT_FILE="$tb_home_folder/.tb/$TBB_HASH_FILENAME"
curl_download_max_time="180"
curl_download_target_url="$TBB_HASH_LINK"
tb_download_common
if [ ! "$curl_exit_code" = "0" ]; then
## Unset those, so during next invocation by tb_download_loop these can
## be set again.
unset TBB_EXTRA_FOLDER
unset TBB_HASH_FILENAME
unset TBB_HASH_LINK
## return 0, so the loop might try the next $tbb_version.
return 0
fi
### archive file ###
[ -n "$TBB_PACKAGE_FILENAME" ] || TBB_PACKAGE_FILENAME="tor-browser-${ARCH_NEW}-${tbb_version}_${TB_LANG}.tar.xz"
[ -n "$TBB_PACKAGE_LINK" ] || TBB_PACKAGE_LINK="$TBB_REMOTE_FOLDER/${TBB_EXTRA_FOLDER}/$TBB_PACKAGE_FILENAME"
tb_notify_details="Downloading Tor Browser... Will take a while..."
echo "INFO: Downloading Tor Browser Bundle: $tbb_version"
echo "\
INFO: Downloading:
$TBB_PACKAGE_LINK ... Will take a while..."
## 1 MB = 1048576 bytes
## 100 MB = 104857600 bytes
## Export CURL_PRGRS_MAX_FILE_SIZE_BYTES, so $CURL_PRGRS can read it.
export CURL_PRGRS_MAX_FILE_SIZE_BYTES="104857600"
## Export CURL_OUT_FILE, so $CURL_PRGRS can read it.
export CURL_OUT_FILE="$tb_home_folder/.tb/$TBB_PACKAGE_FILENAME"
curl_download_max_time="3600"
curl_download_target_url="$TBB_PACKAGE_LINK"
tb_download_common
if [ ! "$curl_exit_code" = "0" ]; then
## Unset those, so during next invocation by tb_download_loop these can
## be set again.
unset TBB_EXTRA_FOLDER
unset TBB_PACKAGE_FILENAME
unset TBB_PACKAGE_LINK
## return 0, so the loop might try the next $tbb_version.
return 0
fi
tb_download_attempt_success="true"
}
tb_gpg_verify() {
echo "INFO:
## Verifying GPG signature.
## Not using the user's GPG keyring also ensures, that the key can be only
## signed by the GPG keys we added. Signatures from random people from the
## user's keyring will be ignored."
gpg_bash_lib_input_verify_timeout_after="60"
gpg_bash_lib_input_verify_kill_after="10"
gpg_bash_lib_input_key_import_dir="/usr/share/torbrowser-updater-keys.d"
gpg_bash_lib_input_temp_folder="$tb_home_folder/.tb/gpgtmpdir"
gpg_bash_lib_input_data_file="$tb_home_folder/.tb/$TBB_HASH_FILENAME"
gpg_bash_lib_input_sig_file="$tb_home_folder/.tb/$TBB_SIG_FILENAME"
gpg_bash_lib_input_file_name_enforce="true"
gpg_bash_lib_input_cleanup="false"
gpg_bash_lib_input_error_handler_extra='tb_error_handler "$gpg_bash_lib_output_error_handler_message"'
## One month has 2592000 seconds.
## (60 [seconds] * 60 [minutes] * 24 [hours] * 30 [days])
## Setting this to 3 months. (777600 seconds)
## (2592000 * 3 [months])
[ -n "$gpg_bash_lib_input_maximum_age_in_seconds" ] || gpg_bash_lib_input_maximum_age_in_seconds="2592000"
source "/usr/lib/gpg-bash-lib/source_all"
trap "gpg_bash_lib_function_error_handler" ERR
gpg_bash_lib_function_main_verify
trap "tb_error_handler" ERR
echo "INFO: gpg_bash_lib_output_gpg_verify_output:
$gpg_bash_lib_output_gpg_verify_output"
if [ ! "$gpg_bash_lib_output_validsig_status" = "true" ]; then
local MSG="<p><b>GPG download signature could NOT be verified.</b>
<br></br>Tor Browser update failed! Try again later.</p>"
$output ${output_opts[@]} --messagex --typex "error" --message "$MSG" --done
$output ${output_opts[@]} --messagecli --typecli "error" --message "$MSG" --done
exit 1
fi
}
tb_hash_verify() {
echo "INFO: Checking hash..."
rm --force "$tb_home_folder/.tb/sha256_output"
local first second
local sha256sum_output sha256sum
local timeout_after kill_after file_name
timeout_after="180"
kill_after="30"
## for relative paths
cd "$tb_home_folder/.tb"
## Debugging.
#timeout_after="0.001"
#kill_after="0.001"
tb_sha_exit_code="0"
timeout --kill-after="$kill_after" "$timeout_after" \
sha256sum "$TBB_PACKAGE_FILENAME" \
> "$tb_home_folder/.tb/sha256_output" \
2>&1 \
\ &
lastpid="$!"
wait "$lastpid" || { tb_sha_exit_code="$?" ; true; };
sha256sum_output="$(cat "$tb_home_folder/.tb/sha256_output")" || true
if grep -q "$sha256sum_output" "$tb_home_folder/.tb/$TBB_HASH_FILENAME" ; then
echo "INFO: Hash check ok."
return 0
fi
echo "ERROR: Hash check failed! Exiting." >&2
local MSG="<p><b>Hash could NOT be verified.</b>
<br></br>Tor Browser update failed! Try again later.</p>"
$output ${output_opts[@]} --messagex --typex "error" --message "$MSG" --done
$output ${output_opts[@]} --messagecli --typecli "error" --message "$MSG" --done
exit 1
}
tb_confirm_install() {
local MSG question button answer type clock_hint
local signature_freshness_msg signature_creation_msg
local last_used_gpg_bash_lib_output_signed_on_date
local last_used_gpg_bash_lib_output_signed_on_unixtime
if [ -f "$tb_home_folder/.tb/last_used_gpg_bash_lib_output_signed_on_date" ]; then
last_used_gpg_bash_lib_output_signed_on_date="$(cat "$tb_home_folder/.tb/last_used_gpg_bash_lib_output_signed_on_date")" || true
fi
if [ "$last_used_gpg_bash_lib_output_signed_on_date" = "" ]; then
last_used_gpg_bash_lib_output_signed_on_date="Unknown. Probably never downloaded a signature before."
fi
if [ -f "$tb_home_folder/.tb/last_used_gpg_bash_lib_output_signed_on_unixtime" ]; then
last_used_gpg_bash_lib_output_signed_on_unixtime="$(cat "$tb_home_folder/.tb/last_used_gpg_bash_lib_output_signed_on_unixtime")" || true
fi