3 TBB_INSTALL
=/usr
/local
/lib
/tor-browser
4 # shellcheck disable=SC2034
5 TBB_PROFILE
=/etc
/tor-browser
/profile
6 # shellcheck disable=SC2034
7 TBB_EXT
=/usr
/local
/share
/tor-browser-extensions
9 # For strings it's up to the caller to add double-quotes ("") around
12 local file name value prefix
16 # Sometimes we might want to do e.g. user_pref
18 [ -e "${file}" ] && sed -i "/^${prefix}(\"${name}\",/d" "${file}"
19 echo "${prefix}(\"${name}\", ${value});" >> "${file}"
22 exec_firefox_helper
() {
23 local binary
="${1}"; shift
25 export LD_LIBRARY_PATH
="${TBB_INSTALL}"
26 export GNOME_ACCESSIBILITY
=1
28 # Don't let Tor Browser manage the tor daemon: we do it ourselves.
29 export TOR_SKIP_LAUNCH
=1
31 # The Tor Browser often assumes that the current directory is
32 # where the browser lives, e.g. for the fixed set of fonts set by
36 # Environment stuff from the upstream start-browser script:
38 # Do not (try to) connect to the session manager. Otherwise it
39 # does (and fails) but if it succeeded it would be "very bad",
40 # although details on why are missing.
41 # https://gitlab.torproject.org/legacy/trac/-/issues/5261
44 # Enable bundled fonts to decrease fingerprint.
45 # https://gitlab.torproject.org/tpo/applications/tor-browser/-/issues/13313
46 export FONTCONFIG_PATH
="${TBB_INSTALL}/fontconfig"
47 export FONTCONFIG_FILE
="fonts.conf"
49 # Avoid overwriting user's dconf values.
50 # https://gitlab.torproject.org/legacy/trac/-/issues/27903
51 export GSETTINGS_BACKEND
=memory
53 exec "${TBB_INSTALL}"/"${binary}" "${@}"
57 exec_firefox_helper firefox.real
"${@}"
60 guess_best_tor_browser_locale
() {
61 local long_locale short_locale similar_locale
62 long_locale
="$(echo "${LANG}" | sed -e 's/\..*$//' -e 's/_/-/')"
63 short_locale
="$(echo "${long_locale}" | cut -d"-" -f1)"
64 if locale_is_supported_by_tor_browser
"$long_locale"; then
67 elif locale_is_supported_by_tor_browser
"$short_locale"; then
68 echo "${short_locale}"
71 # If we use locale xx-YY and Tor Browser supports neither xx-YY nor xx,
72 # there may be a similar locale xx-ZZ that we should use instead.
73 # shellcheck disable=SC2012
75 supported_tor_browser_locales | \
76 grep --max-count=1 --extended-regexp --line-regexp \
77 "${short_locale}-[A-Z]+" \
79 if [ -n "${similar_locale:-}" ]; then
80 echo "${similar_locale}"
87 configure_best_tor_browser_locale
() {
88 local profile best_locale
90 best_locale
="$(guess_best_tor_browser_locale)"
91 cat "/etc/tor-browser/locale-profiles/${best_locale}.js" \
92 >> "${profile}/prefs.js"
95 supported_tor_browser_locales
() {
97 7z e
-tzip -o"$tmp" -- "${TBB_INSTALL}/omni.ja" res
/multilocale.txt
>/dev
/null
98 tr ',' "\n" < "$tmp"/multilocale.txt
102 locale_is_supported_by_tor_browser
() {
104 mozilla_locale
="${1}"
106 supported_tor_browser_locales \
107 |
grep --quiet --fixed-strings --line-regexp "$mozilla_locale"
110 set_firefox_content_process_count
() {
114 set_mozilla_pref
"${profile}/prefs.js" \
115 "dom.ipc.processCount" "$count" \
119 configure_tor_browser_memory_usage
() {
123 system_ram
=$
(awk '/^MemTotal:/ { print $2 }' /proc
/meminfo
)
125 if [ "$system_ram" -lt "$((3 * 1024 * 1024))" ]; then
126 set_firefox_content_process_count
"$profile" 2