tor-browser 2.23 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/sh


# Do not "set -u", else importing gettext.sh dies
# with "ZSH_VERSION: parameter not set".
set -e

. gettext.sh
TEXTDOMAIN="tails"
export TEXTDOMAIN

PROFILE="${HOME}/.tor-browser/profile.default"

14
# Import exec_firefox() and configure_best_tor_browser_locale()
15
16
. /usr/local/lib/tails-shell-library/tor-browser.sh

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
ask_for_confirmation() {
    local dialog_title="`gettext \"Tor is not ready\"`"
    local dialog_text="`gettext \"Tor is not ready. Start Tor Browser anyway?\"`"
    local dialog_start="`gettext \"Start Tor Browser\"`"
    local dialog_cancel="`gettext \"Cancel\"`"
    # zenity can't set the default button to cancel, so we switch the
    # labels and interpret the return value as its negation.
    ! zenity --question \
        --title "$dialog_title" --text="$dialog_text" \
        --cancel-label "$dialog_start" --ok-label "$dialog_cancel"
}

tor_has_bootstrapped() {
    sudo -n -u debian-tor /usr/local/sbin/tor-has-bootstrapped
}

33
34
35
# Workaround bug #8036 by copying any localized search plugins into
# the profile.
enable_localized_searchplugins() {
36
    local locale
37
    locale=$(cat "${PROFILE}"/preferences/0000locale.js | \
38
                 sed 's@^pref("general\.useragent\.locale", "\([^"]*\)");$@\1@')
Tails developers's avatar
Tails developers committed
39
    if [ "${locale}" = en-US ] || [ -e "${PROFILE}"/searchplugins ]; then
40
41
        return
    fi
42
    PLUGIN_DIR="${TBB_INSTALL}"/distribution/searchplugins/locale/${locale}
Tails developers's avatar
Tails developers committed
43
    if [ -d "${PLUGIN_DIR}" ]; then
44
45
46
47
48
        mkdir -p "${PROFILE}"/searchplugins
        # The plugins do not load if they are symlinks
        cp --dereference "${PLUGIN_DIR}"/*  "${PROFILE}"/searchplugins
    fi
}
49
50
51
52
53
54

start_browser() {
    if [ ! -d "${PROFILE}" ]; then
        /usr/local/bin/generate-tor-browser-profile
    fi

55
56
    configure_best_tor_browser_locale "${PROFILE}"

57
58
59
    # Workaround bug #8036
    enable_localized_searchplugins

60
61
62
63
64
65
66
    if [ -z "$XAUTHORITY" ]; then
        XAUTHORITY=~/.Xauthority
        export XAUTHORITY
    fi

    unset SESSION_MANAGER

67
    exec_firefox -allow-remote --class "Tor Browser" -profile "${PROFILE}" "${@}"
68
69
70
71
72
73
74
75
76
77
}


if tor_has_bootstrapped || ask_for_confirmation; then
    # Torbutton 1.5.1+ uses those environment variables
    export TOR_SOCKS_HOST='127.0.0.1'
    export TOR_SOCKS_PORT='9150'

    start_browser "${@}"
fi