10-tbb 7.31 KB
Newer Older
1
2
#!/bin/sh

3
4
set -e
set -u
5
6
7

echo "Install the Tor Browser"

8
9
10
11
12
13
14
# Import the TBB_INSTALL, TBB_PROFILE, TBB_EXT and
# TOR_LAUNCHER_INSTALL variables, which contains the paths we will
# split TBB's actual browser (binaries etc), user data and extension
# into. While this differs from how the TBB organizes the files, the
# end result will be the same, and it's practical since when creating
# a new browser profile we can simply copy the profile directory
# without duplicating all extensions.
15
. /usr/local/lib/tails-shell-library/tor-browser.sh
16
17
# Import install_fake_package
. /usr/local/lib/tails-shell-library/build.sh
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

download_and_verify_files() {
    local base_url bundles destination apt_proxy
    base_url="${1}"
    bundles="${2}"
    destination="${3}"

    # Use the builder's caching APT proxy, if any
    apt_proxy="$(apt-config --format '%v' dump Acquire::http::Proxy)"
    if [ -n "${apt_proxy}" ]; then
        export HTTP_PROXY="${apt_proxy}"
        export http_proxy="${apt_proxy}"
        export HTTPS_PROXY="${apt_proxy}"
        export https_proxy="${apt_proxy}"
    fi

    echo "${bundles}" | while read expected_sha256 tarball; do
        (
            cd "${destination}"
            echo "Fetching ${base_url}/${tarball} ..."
            curl --remote-name "${base_url}/${tarball}"
        )
        actual_sha256="$(sha256sum "${destination}/${tarball}" | cut -d' ' -f1)"
        if [ "${actual_sha256}" != "${expected_sha256}" ]; then
            echo "SHA256 mismatch for ${tarball}" >&2
            exit 1
        fi
    done
}

48
install_tor_browser() {
49
    local bundle destination tmp prep torlauncher_xpi_path torlauncher_version
50
51
52
53
54
    bundle="${1}"
    destination="${2}"

    tmp="$(mktemp -d)"
    tar -xf "${bundle}" -C "${tmp}" tor-browser_en-US
55
    prep="${tmp}"/tor-browser_en-US/Browser
56
57
58
59

    # Enable our myspell/hunspell dictionaries. TBB only provides the
    # one for en-US, but Debian's seems more comprehensive, so we'll
    # only use Debian's dictionaries.
60
    rm -f "${prep}"/dictionaries/*
61
    for f in /usr/share/hunspell/*.aff /usr/share/hunspell/*.dic; do
Tails developers's avatar
Tails developers committed
62
        ln -s "${f}" "${prep}"/dictionaries/
63
64
    done

intrigeri's avatar
intrigeri committed
65
66
    # Let's use the libstdc++ that the Tor Browser is intended to be used with,
    # instead of the system one.
67
68
69
70
    cp "${prep}"/TorBrowser/Tor/libstdc++.so.6 "${prep}"

    # We don't need the Tor binary, the shared libraries Tor needs
    # (but Firefox doesn't) and documentation shipped in the TBB.
71
72
    rm -r "${prep}"/TorBrowser/Tor "${prep}"/TorBrowser/Docs

73
    # We don't want tor-launcher to be part of the regular browser
74
75
76
    # profile but we want to keep it as a standalone application
    # when Tails is started in "bridge mode".
    torlauncher_xpi_path="${prep}/TorBrowser/Data/Browser/profile.default/extensions/tor-launcher@torproject.org.xpi"
77
    7z x -o"${TOR_LAUNCHER_INSTALL}" "${torlauncher_xpi_path}"
78
79
    torlauncher_version="$(sed -n \
        's,^        <em:version>\([0-9\.]\+\)</em:version>,\1,p' \
80
81
        "${TOR_LAUNCHER_INSTALL}/install.rdf")"
    cat > "${TOR_LAUNCHER_INSTALL}/application.ini" << EOF
82
83
84
85
86
87
88
89
90
91
92
93
94
95
[App]
Vendor=TorProject
Name=TorLauncher
Version=${torlauncher_version}
BuildID=$(date +%Y%m%d)
ID=tor-launcher@torproject.org

[Gecko]
MinVersion=$(get_firefox_version "${prep}/application.ini")
MaxVersion=*.*.*

[Shell]
Icon=icon.png
EOF
96
    chmod -R a+rX "${TOR_LAUNCHER_INSTALL}"
97
    rm "${torlauncher_xpi_path}"
98
99

    # The Tor Browser will fail, complaining about an incomplete profile,
100
    # unless there's a readable TorBrowser/Data/Browser/Caches
101
    # in the directory where the firefox executable is located.
102
103
104
    mkdir -p "${prep}"/TorBrowser/Data/Browser/Caches

    mv "${prep}" "${destination}"
105
106
107
108

    rm -r "${tmp}"
}

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
install_langpacks_from_bundles() {
    local bundles_dir destination
    bundles_dir="${1}"
    destination="${2}"

    for tarball in "${bundles_dir}"/tor-browser-*.tar.xz; do
        locale="$(echo "${tarball}" | sed "s@^.*/tor-browser-.*_\(.*\)\.tar\.xz@\1@")"
        if [ "${locale}" = en-US ]; then
            continue
        fi
        xpi="tor-browser_${locale}/Browser/TorBrowser/Data/Browser/profile.default/extensions/langpack-${locale}@firefox.mozilla.org.xpi"
        (
            cd "${bundles_dir}"
            tar -xf "${tarball}" "${xpi}"
            mv "${xpi}" "${destination}"
        )
    done
}

128
129
130
131
132
133
134
135
get_firefox_version() {
    # The application.ini file
    local appini
    appini="${1}"
    sed -n 's/^Version=\(.*\)$/\1/p' "${appini}"
}

install_debian_extensions() {
136
137
    local destination
    destination="${1}"
138
    shift
139
    apt-get install --yes "${@}"
spriver's avatar
spriver committed
140
141
    ln -s /usr/share/xul-ext/ublock-origin/ \
          "${destination}"/'uBlock0@raymondhill.net'
142
143
}

144
create_default_profile() {
145
146
147
    local tbb_profile extensions_dir destination
    tbb_profile="${1}"
    tbb_extensions_dir="${2}"
148
149
150
    destination="${3}"

    rsync -a --exclude bookmarks.html --exclude extensions \
151
          "${tbb_profile}"/ "${destination}"/
152
153
154
155
156

    # Remove TBB's default bridges
    sed -i '/extensions\.torlauncher\.default_bridge\./d' "${destination}"/preferences/extension-overrides.js

    mkdir -p "${destination}"/extensions
157
    for ext in "${tbb_extensions_dir}"/*; do
158
159
160
161
        ln -s "${ext}" "${destination}"/extensions/
    done
}

Tails developers's avatar
Tails developers committed
162
TBB_SHA256SUMS_FILE=/usr/share/tails/tbb-sha256sums.txt
Tails developers's avatar
Tails developers committed
163
TBB_TARBALLS="$(grep "\<tor-browser-linux32-.*\.tar.xz$" "${TBB_SHA256SUMS_FILE}")"
164

Tails developers's avatar
Tails developers committed
165
166
# We'll use the en-US bundle as our basis; only langpacks will be
# installed from the other bundles.
Tails developers's avatar
Tails developers committed
167
MAIN_TARBALL="$(echo "${TBB_TARBALLS}" | grep -o "tor-browser-linux32-.*_en-US.tar.xz")"
Tails developers's avatar
Tails developers committed
168
TBB_DIST_URL_FILE=/usr/share/tails/tbb-dist-url.txt
169
TBB_TARBALLS_BASE_URL="$(cat "${TBB_DIST_URL_FILE}")"
170

171
172
# The Debian Iceweasel extensions we want to install and make
# available in the Tor Browser.
spriver's avatar
spriver committed
173
DEBIAN_EXT_PKGS="xul-ext-ublock-origin"
174

175
TMP="$(mktemp -d)"
Tails developers's avatar
Tails developers committed
176
download_and_verify_files "${TBB_TARBALLS_BASE_URL}" "${TBB_TARBALLS}" "${TMP}"
177

Tails developers's avatar
Tails developers committed
178
install_tor_browser "${TMP}/${MAIN_TARBALL}" "${TBB_INSTALL}"
179

180
181
mkdir -p "${TBB_EXT}"
install_langpacks_from_bundles "${TMP}" "${TBB_EXT}"
182

183
184
rm -r "${TMP}"

Tails developers's avatar
Tails developers committed
185
# Let's put all the extensions from TBB in the global extensions
186
# directory...
187
188
mv "${TBB_INSTALL}"/TorBrowser/Data/Browser/profile.default/extensions/* "${TBB_EXT}"
rmdir "${TBB_INSTALL}"/TorBrowser/Data/Browser/profile.default/extensions
189

190
191
# ... and then install a few Iceweasel extension by using a fake
# Iceweasel equivs package to satisfy the dependencies.
192
FIREFOX_VERSION=$(get_firefox_version "${TBB_INSTALL}"/application.ini)
193
FAKE_ICEWEASEL_VERSION=${FIREFOX_VERSION}+fake1
194
install_fake_package iceweasel "${FAKE_ICEWEASEL_VERSION}" web
195
install_debian_extensions "${TBB_EXT}" ${DEBIAN_EXT_PKGS}
196

197
mkdir -p "${TBB_PROFILE}"
198
create_default_profile "${TBB_INSTALL}"/TorBrowser/Data/Browser/profile.default "${TBB_EXT}" "${TBB_PROFILE}"
199

200
201
202
203
# Create a copy of the Firefox binary, for use e.g. by Tor Launcher.
# It won't be subject to AppArmor confinement.
cp -a "${TBB_INSTALL}/firefox" "${TBB_INSTALL}/firefox-unconfined"

204
205
chown -R root:root "${TBB_INSTALL}" "${TBB_PROFILE}" "${TBB_EXT}"
chmod -R a+rX "${TBB_INSTALL}" "${TBB_PROFILE}" "${TBB_EXT}"
206

Tails developers's avatar
Tails developers committed
207
# Make the Tor Browser into the system's default web browser
208
209
update-alternatives --install /usr/bin/x-www-browser x-www-browser /usr/local/bin/tor-browser 99
update-alternatives --install /usr/bin/gnome-www-browser gnome-www-browser /usr/local/bin/tor-browser 99
210
sed -i 's/\<iceweasel\.desktop\>/tor-browser.desktop/' /etc/gnome/defaults.list