/
update-torbrowser
executable file
·2028 lines (1726 loc) · 70.9 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
## Copyright (C) 2012 - 2020 ENCRYPTED SUPPORT LP <adrelanos@riseup.net>
## See the file COPYING for copying conditions.
if [ ! "$tpo_downloader_debug" = "" ]; then
if [ "$tpo_downloader_debug" -ge "1" ]; then
set -x
fi
fi
set -o pipefail
set -o errtrace
[ -n "$SCRIPTNAME" ] || SCRIPTNAME="$(basename "$BASH_SOURCE")"
[ -n "$ICON" ] || 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 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
## - RecommendedTBBVersions format is not finalized
## https://trac.torproject.org/projects/tor/ticket/14383
## - counter downgrade / stale mirror attacks on RecommendedTBBVersions - sign / verify tbb versions file
## https://trac.torproject.org/projects/tor/ticket/13065
## - GETINFO consensus/packages exists but not yet populated.
## https://trac.torproject.org/projects/tor/ticket/10395
## - Using torbrowser-launcher instead of tb-updater in Whonix
## https://forums.whonix.org/t/using-torbrowser-launcher-instead-of-tb-updater-in-whonix/385
tb_exit_function() {
trap "" ERR
local exit_code
exit_code="$1"
if [ "$exit_code" = "0" ]; then
exit 0
fi
if [ "$anon_shared_inst_tb" = "open" ]; then
if [ "$tb_postinst" = "true" ]; then
echo "\
INFO: Failing open. More info:
https://www.whonix.org/wiki/$tb_wiki#tb-updater_postinst"
fi
exit 0
else
if [ "$tb_postinst" = "true" ]; then
echo "\
INFO: Failing closed. More info:
https://www.whonix.org/wiki/$tb_wiki#tb-updater_postinst"
fi
exit "$exit_code"
fi
}
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/$tb_wiki>https://www.whonix.org/wiki/$tb_wiki</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>"
[ -n "$tb_user_home" ] || tb_user_home=~
[ -n "$tb_install_folder" ] || tb_install_folder="tb"
mkdir --parents "$tb_user_home/.cache/$tb_install_folder"
echo "$MSG" >> "$tb_user_home/.cache/$tb_install_folder/torbrowser_updater_error.log"
## In case variable output is not set yet.
[ -n "$output" ] || output="output"
## In case function $output does not exist yet.
if [ ! "$(type -t "$output")" = "function" ]; then
output="echo"
fi
if [ "$progressbaridx" = "" ]; then
true
else
$output ${output_opts[@]} --progressbaridx "$progressbaridx" --progressx "100" || true
progressbaridx=""
fi
$output ${output_opts[@]} --messagex --titlex "$TITLE" --typex "error" --message "$MSG" --done
$output ${output_opts[@]} --messagecli --titlecli "$TITLE" --typecli "error" --message "$MSG" --done
tb_exit_function 1
}
trap "tb_error_handler" ERR
download_fail_help_set() {
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>- $tb_title Downloader (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/Stay_Tuned>https://www.whonix.org/wiki/Stay_Tuned</a>
<br></br>- Manually update: <a href=https://www.whonix.org/wiki/$tb_wiki/Manual_Download>https://www.whonix.org/wiki/$tb_wiki/Manual_Download</a>
</p>"
}
tb_run_function() {
case $tb_skip_functions in
*"$@"*) echo "INFO: Skipping $@, because tb_skip_functions includes it."
return 0
;;
esac
true "INFO: Running $@, because tb_skip_functions does not include it."
"$@"
}
root_check() {
if [ -e /run/qubes/this-is-templatevm ]; then
return 0
fi
if echo "$@" | grep -q "\-\-postinst" ; then
return 0
fi
if [ "$(id -u)" != "0" ]; then
#echo "$SCRIPTNAME running as user."
true
else
echo "ERROR: Do not run $SCRIPTNAME as root!"
tb_exit_function 2
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
command -v /usr/lib/msgcollector/pv_wrapper >/dev/null
command -v /usr/lib/msgcollector/striphtml >/dev/null
## tbbversion function
command -v grep >/dev/null
## tbbversion function
command -v sed >/dev/null
command -v sort >/dev/null
command -v pv >/dev/null
command -v mkfifo >/dev/null
command -v jq >/dev/null
}
tb_ex_funct() {
local MSG
MSG="$SIGNAL_TYPE received. Cleaning up..."
if [ "$last_pid_list" = "" ]; then
true
else
for pid in $last_pid_list; do
kill -1 "$pid"
done
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
#echo "ERROR: $MSG"
MSG="$SIGNAL_TYPE received. Exiting."
$output ${output_opts[@]} --messagecli --typecli "info" --message "$MSG" --done
}
tb_signal_sigterm() {
SIGNAL_TYPE="sigterm"
tb_ex_funct
tb_exit_function 143
}
trap "tb_signal_sigterm" SIGTERM
tb_signal_sigint() {
SIGNAL_TYPE="sigint"
tb_ex_funct
tb_exit_function 130
}
trap "tb_signal_sigint" SIGINT ## ctrl + c
trap_sigusr2() {
SIGNAL_TYPE="SIGUSR2"
tb_ex_funct
tb_exit_function 3
}
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="true"
shift
;;
--update)
true ## legacy
shift
;;
--noask)
TB_FORCE_INSTALL="1"
shift
;;
--nokilltb)
NOKILLTB="1"
shift
;;
--devbuildpassthrough)
TB_FORCE_INSTALL="1"
DEV_BUILD_PASSTHROUGH="1"
DEV_PASSTHROUGH="1"
## Use export so it can be read by CURL_PRGRS.
[ -n "$TB_USE_MSGCOLLECTOR" ] || export TB_USE_MSGCOLLECTOR="false"
shift
;;
--postinst)
tb_postinst="true"
shift
;;
--is-chroot)
is_chroot="true"
shift
;;
--noaskstart)
noaskstart="true"
shift
;;
--language)
TB_LANG="$2"
shift 2
;;
--no-tor-con-check)
TB_NO_TOR_CON_CHECK="1"
shift 1
;;
--input)
TB_INPUT="$2"
shift 2
;;
--no-install)
TB_NO_INSTALL="true"
shift
;;
--resume)
CURL_RESUME="-C -"
## XXX: Looks like curl-prgrs does not support '-C -'.
## Therefore also implying '--ordinary' progress bar when
## using --resume.
[ -n "$ordinary" ] || ordinary="true"
shift
;;
--onion)
[ -n "$tb_onion" ] || tb_onion="true"
shift
;;
--)
shift
break
;;
-*)
echo "$SCRIPTNAME unknown option: $1"
echo "See:"
echo " man $SCRIPTNAME"
tb_exit_function 4
;;
*)
break
;;
esac
done
## If there are input files (for example) that follow the options, they
## will remain in the "$@" positional parameters.
true "$BASH_SOURCE \$@: $@"
}
tb_stdin() {
if [ ! "$TB_INPUT" = "" ]; then
true "INFO: TB_INPUT is already set to $TB_INPUT, skipping auto detection, ok."
return 0
fi
if [ "$TB_FORCE_INSTALL" = "1" ]; then
echo "INFO: TB_FORCE_INSTALL is set to '1', therefore setting TB_INPUT to 'none'."
TB_INPUT="none"
TB_USE_MSGCOLLECTOR="false"
return 0
fi
if [ -t "0" ]; then
echo "INFO: stdin connected to terminal, setting \
TB_INPUT to stdin, will use terminal for input, ok."
echo "INFO: Alternatively, if want to run from \
command line, but still use the graphical user interface for input, \
you could add to command line: --input gui"
TB_INPUT="stdin"
TB_USE_MSGCOLLECTOR="false"
return 0
fi
echo "INFO: stdin not connected to terminal, probably run in graphical environment, ok."
}
tb_qubes_dvm_template() {
if echo "$qubes_vm_name" | grep -q --invert-match "\-dvm" ; then
echo "INFO: not running inside Qubes DVM Template, ok."
return 0
fi
local MSG="\
<p>Do not run $TITLE in Qubes DVM Template!<br></br>
<br></br>
More info: <a href=https://www.whonix.org/wiki/$tb_wiki#Running_in_Qubes_DVM_Template>https://www.whonix.org/wiki/$tb_wiki#Running_in_Qubes_DVM_Template</a></p>"
$output ${output_opts[@]} --messagex --titlex "$TITLE" --typex "error" --message "$MSG" --done
local MSG_CLI
MSG_CLI="$(/usr/lib/msgcollector/striphtml "$MSG")"
echo "ERROR: $MSG_CLI"
tb_exit_function 1
}
output() {
outputfunc "$@"
}
outputfunc() {
true "$FUNCNAME: args: ${1+$@}"
if [ "$output_tool" = "" ]; then
local TB_USE_MSGCOLLECTOR
TB_USE_MSGCOLLECTOR="false"
fi
if [ "$TB_USE_MSGCOLLECTOR" = "false" ]; then
while true; do
case $1 in
--messagex)
## Only show --messagecli. Skip --messagex.
return 0
;;
--message)
local MSG
MSG="$2"
shift 2
break
;;
*)
break
;;
esac
done
MSG="$(/usr/lib/msgcollector/striphtml "$MSG")"
if [ ! "$MSG" = "" ]; then
echo "$MSG"
fi
elif [ "$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" "$@"
else
$output_tool --identifier "$IDENTIFIER" --whoami "$who_ami" "$@"
fi
true
}
## Make it visible to curl-prgrs.
export -f output
export -f outputfunc
tb_config_folder_parser() {
true "tb_settings_folder: $tb_settings_folder"
[ -n "$tb_settings_folder" ] || tb_settings_folder="torbrowser.d"
shopt -s nullglob
local i
for i in \
/etc/${tb_settings_folder}/*.conf \
/rw/config/${tb_settings_folder}/*.conf \
/usr/local/etc/${tb_settings_folder}/*.conf \
; do
bash -n "$i"
source "$i"
done
}
tb_resolv_conf_debugging() {
ls -la /etc/resolv.conf || true
cat /etc/resolv.conf || true
cat /etc/resolv.whonix || true
cat /etc/resolv.conf.whonix-orig || true
}
tb_anon_ws_dns_conf() {
true "tb_disable_anon_ws_dnf_conf: $tb_disable_anon_ws_dnf_conf"
if [ "$tb_disable_anon_ws_dnf_conf" = "true" ]; then
## Check if /etc/resolv.conf is a symlink. This is only the case
## when whonix-ws-network-conf is already installed.
if test -h /etc/resolv.conf ; then
if test -x /var/lib/dpkg/info/whonix-ws-network-conf.prerm ; then
[ -n "$tb_reenable_anon_ws_dnf_conf" ] || tb_reenable_anon_ws_dnf_conf=true
tb_resolv_conf_debugging
## Restore original /etc/resolv.conf.
sudo --non-interactive /usr/lib/tb-updater/chroot-pre
tb_resolv_conf_debugging
fi
fi
fi
}
tb_settings_chroot_common() {
## Do not run in chroot if tb_install_in_chroot=false.
if [ ! "$tb_install_in_chroot" = "false" ]; then
[ -n "$tb_updater_run" ] || tb_updater_run=true
fi
## Fail closed, if there was an error.
[ -n "$anon_shared_inst_tb" ] || anon_shared_inst_tb=closed
## Skip Tor connectivity check when running inside chroot.
[ -n "$TB_NO_TOR_CON_CHECK" ] || TB_NO_TOR_CON_CHECK="1"
## Hack to disable using proxy settings when running inside chroot.
## We are using --fail anyhow. No problem to duplicate it.
[ -n "$CURL_PROXY" ] || CURL_PROXY="--fail"
[ -n "$tb_disable_anon_ws_dnf_conf" ] || tb_disable_anon_ws_dnf_conf=true
}
tb_settings_postinst_common() {
## Skip update [version] confirmation messages when running with
## --postinst, because we will be using hardcoded version numbers.
[ -n "$tb_confirm_update_skip" ] || tb_confirm_update_skip=true
## Skip installation confirmation messages when running with
## --postinst, because we will be using hardcoded version numbers.
## Downgrade / free attacks should not be possible, because file names
## that include the version number will be verified from the gpg verified
## sha256sum sums file.
[ -n "$tb_confirm_installation_skip" ] || tb_confirm_installation_skip=true
[ -n "$NOKILLTB" ] || NOKILLTB="1"
[ -n "$noaskstart" ] || noaskstart="true"
[ -n "$TB_INPUT" ] || TB_INPUT="none"
## Use export so it can be read by CURL_PRGRS.
[ -n "$TB_USE_MSGCOLLECTOR" ] || export TB_USE_MSGCOLLECTOR="false"
[ -n "$tbb_use_hardcoded_version" ] || tbb_use_hardcoded_version="true"
## Fail open, if there was an error.
[ -n "$anon_shared_inst_tb" ] || anon_shared_inst_tb=open
}
tb_settings_qubes_common_templatevm() {
## Skip Tor connectivity check when running inside Qubes TempalteVM,
## because since Qubes R4 TemplateVMs are non-networked by default.
[ -n "$TB_NO_TOR_CON_CHECK" ] || TB_NO_TOR_CON_CHECK="1"
}
tb_settings_qubes_postinst_templatevm() {
## Do not run during Qubes TempalteVM postinst if tb_install_follow=false.
if [ ! "$tb_install_follow" = "false" ]; then
[ -n "$tb_updater_run" ] || tb_updater_run=true
fi
if [ "$tb_user_home" = "" ]; then
tb_user_home="/var/cache/tb-binary"
tb_auto_set_user_home_msg="Automatically setting download folder to $tb_user_home, because running inside Qubes TemplateVM and from postinst. \
This is useful so you get up to date versions of $tb_title in newly created AppVMs inherited from updated TemplateVMs.
More info: https://www.whonix.org/wiki/$tb_wiki#Qubes_specific"
fi
}
tb_settings_qubes_manual_run_templatevm() {
[ -n "$tb_updater_run" ] || tb_updater_run=true
if [ "$tb_user_home" = "" ]; then
tb_user_home="/var/cache/tb-binary"
tb_auto_set_user_home_msg="Automatically setting download folder to $tb_user_home, because running inside Qubes TemplateVM but not run from postinst. \
This is useful so you get up to date versions of $tb_title in newly created AppVMs inherited from updated TemplateVMs.
More info: https://www.whonix.org/wiki/$tb_wiki#Qubes_specific"
fi
}
tb_settings_manual_run_common() {
[ -n "$tb_updater_run" ] || tb_updater_run=true
}
tb_preparation() {
[ -n "$tb_wiki" ] || tb_wiki="Tor_Browser"
[ -n "$tb_title" ] || tb_title="Tor Browser"
if [ ! "$tb_postinst" = "true" ]; then
[ -n "$tb_manual_run" ] || tb_manual_run=true
fi
if command -v qubesdb-read >/dev/null 2>&1 ; then
[ -n "$is_qubes" ] || is_qubes=true
if [ "$qubes_vm_type" = "" ]; then
## Works since Qubes R3.2.
if [ -e /run/qubes/this-is-appvm ]; then
qubes_vm_type="AppVM"
fi
if [ -e /run/qubes/this-is-netvm ]; then
qubes_vm_type="NetVM"
fi
if [ -e /run/qubes/this-is-templatevm ]; then
qubes_vm_type="TemplateVM"
fi
if [ "$is_chroot" = "true" ]; then
qubes_vm_type="TemplateVM"
fi
fi
## qubesdb-read fails
## - inside chroot,
## - perhaps during upgrades
## - https://github.com/QubesOS/qubes-issues/issues/2497
## - https://github.com/QubesOS/qubes-issues/issues/2509
## therefore overwriting with '|| true'.
[ -n "$qubes_vm_name" ] || qubes_vm_name="$(qubesdb-read /name)" || true
## For Qubes R3.1 compatibility.
[ -n "$qubes_vm_type" ] || qubes_vm_type="$(qubesdb-read /qubes-vm-type)" || true
else
[ -n "$is_qubes" ] || is_qubes=false
fi
if [ "$qubes_vm_type" = "TemplateVM" ]; then
if [ "$(id -u)" != "0" ]; then
echo "ERROR: Needs to run as root in Qubes TemplateVM. Run:"
echo "sudo $SCRIPTNAME"
tb_exit_function 2
else
true
fi
fi
if [ "$is_chroot" = "true" ]; then
tb_settings_chroot_common
fi
if [ "$qubes_vm_type" = "TemplateVM" ]; then
tb_settings_qubes_common_templatevm
fi
if [ "$tb_postinst" = "true" ]; then
tb_settings_postinst_common
if [ "$qubes_vm_type" = "TemplateVM" ]; then
tb_settings_qubes_postinst_templatevm
fi
fi
if [ "$tb_manual_run" = "true" ]; then
tb_settings_manual_run_common
if [ "$qubes_vm_type" = "TemplateVM" ]; then
tb_settings_qubes_manual_run_templatevm
fi
fi
if [ "$tb_user_home" = "" ]; then
tb_user_home=~
## In case of running as root from postinst.
if [ "$tb_user_home" = "/root" ] || [ "$(whoami)" = "root" ]; then
tb_user_home="/var/cache/tb-binary"
tb_auto_set_user_home_msg="Automatically setting download folder to $tb_user_home, because running as root."
fi
fi
[ -n "$IDENTIFIER" ] || IDENTIFIER="torbrowser-downloader"
[ -n "$tb_install_folder" ] || tb_install_folder="tb"
[ -n "$tb_install_folder_dot" ] || tb_install_folder_dot=".tb"
[ -n "$tb_browser_name" ] || tb_browser_name="tor-browser"
[ -n "$tb_bin" ] || tb_bin="torbrowser"
[ -n "$tb_home_folder" ] || tb_home_folder="$tb_user_home/$tb_install_folder_dot"
[ -n "$tb_browser_folder" ] || tb_browser_folder="$tb_home_folder/$tb_browser_name"
[ -n "$tb_cache_folder" ] || tb_cache_folder="$tb_user_home/.cache/$tb_install_folder"
[ -n "$tb_temp_folder" ] || tb_temp_folder="$tb_cache_folder/temp"
[ -n "$tb_downloaded_files_folder" ] || tb_downloaded_files_folder="$tb_cache_folder/files"
[ -n "$tb_gpg_tmp_dir" ] || tb_gpg_tmp_dir="$tb_cache_folder/gpgtmpdir"
[ -n "$tb_extract_temp_folder" ] || tb_extract_temp_folder="$tb_cache_folder/$tb_browser_name"
[ -n "$tb_local_version_file" ] || tb_local_version_file="$tb_browser_folder/Browser/tbb_version.json"
[ -n "$tbb_download_alpha_version" ] || tbb_download_alpha_version="false"
[ -n "$TB_KEEP_OLD_VERSIONS_COUNT" ] || TB_KEEP_OLD_VERSIONS_COUNT="0"
if [ ! "$tb_updater_run" = "true" ]; then
true "tb_updater_run is set to: $tb_updater_run"
true "therefore running: tb_exit_function 0"
tb_exit_function 0
fi
if [ "$tb_postinst" = "true" ]; then
## Being careful with deletion.
if [ "$tb_downloaded_files_folder" = "/var/cache/tb-binary/.cache/$tb_install_folder/files" ]; then
echo "rm -r -f '$tb_downloaded_files_folder'"
rm -r -f "$tb_downloaded_files_folder"
fi
fi
## Required for /usr/lib/helper-scripts/tor_bootstrap_check.bsh.
TEMP_DIR="$tb_temp_folder"
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"
if [ "$ARCH" = "" ]; then
echo "INFO: Auto detecting ARCH..."
ARCH="$(uname --machine)"
echo "INFO: ARCH $ARCH detected."
else
echo "INFO: Skipping auto detecting ARCH because already set."
echo "INFO: ARCH is set to $ARCH."
fi
if [ "$ARCH_DOWNLOAD" = "" ]; then
echo "INFO: Auto detecting ARCH_DOWNLOAD..."
if [ "$ARCH" = "i386" ]; then
[ -n "$ARCH_DOWNLOAD" ] || ARCH_DOWNLOAD="linux32"
elif [ "$ARCH" = "i686" ]; then
[ -n "$ARCH_DOWNLOAD" ] || ARCH_DOWNLOAD="linux32"
else
## NOTE: A simple else is non-ideal, should there be ever more architectures.
[ -n "$ARCH_DOWNLOAD" ] || ARCH_DOWNLOAD="linux64"
fi
echo "INFO: ARCH_DOWNLOAD $ARCH_DOWNLOAD detected."
else
echo "INFO: Skipping auto detecting ARCH_DOWNLOAD because already set."
echo "INFO: ARCH_DOWNLOAD is set to $ARCH_DOWNLOAD."
fi
## provides tbbversion function
source /usr/lib/tbbversion_parser
if [ "$display" = "" ]; then
if [ "$DISPLAY" = "" ]; then
display=":0"
else
display="$DISPLAY"
fi
fi
if [ "$my_tty" = "" ]; then
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
fi
who_ami="$(whoami)"
TITLE="$tb_title Downloader (by Whonix developers)"
output_tool="/usr/lib/msgcollector/msgcollector"
output="output"
$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"
echo "ERROR: $MSG"
EXIT_CODE="1"
return 0
fi
fi
if [ "$CURL_PRGRS" = "" ]; then
if [ "$ordinary" = "true" ]; then
CURL_PRGRS="$CURL"
elif [ -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
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"
mkdir --parents "$tb_cache_folder"
mkdir --parents "$tb_downloaded_files_folder"
if [ "$tb_onion" = "true" ]; then
[ -n "$tbb_download_base_url" ] || tbb_download_base_url="http://rqef5a5mebgq46y5.onion"
## https://web.archive.org/web/20201213115438/https://securityheaders.com/?q=https%3A%2F%2Faus1.torproject.org%2Ftorbrowser%2Fupdate_3%2Frelease%2Fdownloads.json&followRedirects=off
## Onion-Location http://x3nelbld33llasqv.onion/torbrowser/update_3/release/downloads.json
[ -n "$TBB_VERSIONS_FILE_LINK" ] || TBB_VERSIONS_FILE_LINK="http://x3nelbld33llasqv.onion/torbrowser/update_3/release/downloads.json"
else
## Download from the torproject.org clearnet by default.
[ -n "$tbb_download_base_url" ] || tbb_download_base_url="https://dist.torproject.org"
[ -n "$TBB_VERSIONS_FILE_LINK" ] || TBB_VERSIONS_FILE_LINK="https://aus1.torproject.org/torbrowser/update_3/release/downloads.json"
[ -n "$CURL_FORCE_SSL" ] || CURL_FORCE_SSL="--tlsv1.3 --proto =https"
fi
[ -n "$TBB_REMOTE_FOLDER" ] || TBB_REMOTE_FOLDER="$tbb_download_base_url/torbrowser"
if [ "$DEV_PASSTHROUGH" = "1" ]; then
[ -n "$CURL_PROXY" ] || CURL_PROXY=""
elif [ "$qubes_vm_type" = "TemplateVM" ]; then
## Use Qubes updates proxy.
if [ "$CURL_PROXY" = "" ]; then
if systemctl -q is-active qubes-updates-proxy-forwarder.socket; then
PROXY_SERVER='http://127.0.0.1:8082/'
else
PROXY_SERVER='http://10.137.255.254:8082/'
fi
CURL_PROXY="--proxy $PROXY_SERVER"
fi
elif [ -f /usr/share/whonix/marker ]; then
## sets: GATEWAY_IP
eval $(/usr/lib/helper-scripts/settings_echo)
[ -n "$SOCKS_PORT_TBB_DOWNLOAD" ] || SOCKS_PORT_TBB_DOWNLOAD="9115"
if [ "$socks_user_name" = "" ]; then
local uuid_temp
uuid_temp="$(cat "/proc/sys/kernel/random/uuid")"
socks_user_name="tb-updater"
socks_user_name="${socks_user_name}_${uuid_temp}"
fi
[ -n "$CURL_PROXY" ] || CURL_PROXY="--proxy socks5h://$socks_user_name:password@$GATEWAY_IP:$SOCKS_PORT_TBB_DOWNLOAD"
else
[ -n "$CURL_PROXY" ] || CURL_PROXY=""
fi
echo "INFO: CURL_PROXY: $CURL_PROXY"
## Also used by function tbbversion.
[ -n "$RecommendedTBBVersions" ] || RecommendedTBBVersions="$tb_cache_folder/RecommendedTBBVersions"
[ -n "$tbb_version_last_downloaded_save_file" ] || tbb_version_last_downloaded_save_file="$tb_cache_folder/tbb_version_last_downloaded_save_file"
if [ -f "$tbb_version_last_downloaded_save_file" ]; then
[ -n "$tbb_version_previous_downloaded_version" ] || tbb_version_previous_downloaded_version="$(cat "$tbb_version_last_downloaded_save_file")"
fi
[ -n "$tbb_version_previous_downloaded_version" ] || tbb_version_previous_downloaded_version="none"
if ! test -f /usr/share/whonix/marker ; then
[ -n "$TB_NO_TOR_CON_CHECK" ] || TB_NO_TOR_CON_CHECK="1"
fi
if [ ! "$tb_auto_set_user_home_msg" = "" ]; then
echo "INFO: $tb_auto_set_user_home_msg"
fi
}
tb_skip_if_higher_or_equal_version_already_downloaded() {
if [ ! "$tb_postinst" = "true" ]; then
return 0
fi
if [ "$tbb_version_previous_downloaded_version" = "none" ]; then
return 0
fi
if [ "$tbb_version" = "" ]; then
return 0
fi
if dpkg --compare-versions "$tbb_version_previous_downloaded_version" ge "$tbb_version" ; then
echo "INFO: tbb_version_previous_downloaded_version: $tbb_version_previous_downloaded_version is greater or equal $tbb_version, therefore skipping to download, ok."
tb_exit_function 0
fi
}
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 [ "$CURL_PROXY" = "" ]; then
return 0
fi
if [ -x /usr/lib/helper-scripts/tor_enabled_check ]; then
echo -n "INFO: Running Tor enabled check... "
source /usr/lib/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 downloading $tb_title still fails, please report a bug!</p>
<p>Debugging information:<br />
You could use <code>--no-tor-con-check</code> if you think function <code>$FUNCNAME</code> should be skipped.</p>"
$output ${output_opts[@]} --messagex --typex "error" --message "$MSG" --done
local MSG_CLI
MSG_CLI="$(/usr/lib/msgcollector/striphtml "$MSG")"
echo "ERROR: $MSG_CLI"
tb_exit_function 5
fi
echo "Done."
else
true "/usr/lib/helper-scripts/tor_enabled_check does not exist, skipping."
fi
if [ -x /usr/lib/helper-scripts/tor_bootstrap_check.bsh ]; then
echo -n "INFO: Running Tor bootstrap check... "
source /usr/lib/helper-scripts/tor_bootstrap_check.bsh
## sets: tor_bootstrap_percent
tb_run_function check_tor_circuit_established
if [ ! "$tor_circuit_established" = "1" ]; 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 downloading $tb_title still fails, please report a bug!</p>"
$output ${output_opts[@]} --messagex --typex "error" --message "$MSG" --done
local MSG_CLI
MSG_CLI="$(/usr/lib/msgcollector/striphtml "$MSG")"
echo "ERROR: $MSG_CLI"
tb_exit_function 6
fi
echo "Done."
else
true "/usr/lib/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... Downloading: $tbb_download_base_url ..."
[ -n "$timeout_connectivity_checks_curl" ] || timeout_connectivity_checks_curl=180
## 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_temp_folder/tbb_remote_folder"
rm -f "$CURL_OUT_FILE"
curl_download_max_time="$timeout_connectivity_checks_curl"
curl_download_target_url="$tbb_download_base_url"
tb_download_common_exit_on_fail="false"
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 downloading $tb_title 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
local MSG_CLI
MSG_CLI="$(/usr/lib/msgcollector/striphtml "$MSG")"
echo "ERROR: $MSG_CLI"
tb_exit_function 7
fi
echo "INFO: Connectivity check succeeded."
}
tb_update_check() {
if [ ! "$tbb_version" = "" ]; then
true "INFO: tbb_version already set to '$tbb_version'. Skipping $FUNCNAME, ok."
return 0
fi
## do not re-download Tor Browser if a previous build already did
if [ "$DEV_BUILD_PASSTHROUGH" = "1" ]; then
if [ -d "$tb_browser_folder" ]; then
echo "$SCRIPTNAME: Not downloading $tb_title again, because $tb_browser_folder already exists."
tb_exit_function 0
fi
fi
tb_notify_details="Checking $tb_title version... Will take a moment..."
echo "INFO: Find out latest version... Downloading: $TBB_VERSIONS_FILE_LINK ..."