i2p-browser 4.25 KB
Newer Older
Kill Your TV's avatar
Kill Your TV committed
1 2 3
#!/bin/sh

set -e
4
set -u
Kill Your TV's avatar
Kill Your TV committed
5

6 7 8 9
. gettext.sh
TEXTDOMAIN="tails"
export TEXTDOMAIN

10
# Import the TBB_EXT variable, and guess_best_tor_browser_locale().
11 12
. /usr/local/lib/tails-shell-library/tor-browser.sh

Tails developers's avatar
Tails developers committed
13 14 15 16
# Import try_cleanup_browser_chroot(), setup_browser_chroot(),
# configure_chroot_dns_servers(), configure_chroot_browser(),
# configure_chroot_browser(), set_chroot_browser_locale()
# set_chroot_torbutton_browser_name(), set_chroot_browser_permissions()
17
# and run_browser_in_chroot().
18
. /usr/local/lib/tails-shell-library/chroot-browser.sh
Tails developers's avatar
Tails developers committed
19

20
# Import i2p_router_console_is_ready() and i2p_is_enabled().
21
. /usr/local/lib/tails-shell-library/i2p.sh
22

23 24 25 26 27 28
error () {
    local cli_text="${CMD}: `gettext \"error:\"` ${@}"
    local dialog_text="<b><big>`gettext \"Error\"`</big></b>

${@}"
    echo "${cli_text}" >&2
29
    sudo -u "${SUDO_USER}" zenity --error --title "" --text "${dialog_text}"
30 31 32
    exit 1
}

Kill Your TV's avatar
Kill Your TV committed
33 34 35 36 37 38 39 40 41
verify_start () {
    # Make sure the user really wants to start the browser in case the router console isn't available
    local dialog_msg="<b><big>`gettext \"Do you still want to launch I2P Browser?\"`</big></b>

`gettext \"The I2P router console is not ready.\"`"
    local launch="`gettext \"_Launch\"`"
    local exit="`gettext \"_Exit\"`"
    # Since zenity can't set the default button to cancel, we switch the
    # labels and interpret the return value as its negation.
42
    if sudo -u "${SUDO_USER}" zenity --question --title "" --ok-label "${exit}" \
Kill Your TV's avatar
Kill Your TV committed
43 44 45 46 47 48 49 50 51 52 53
       --cancel-label "${launch}" --text "${dialog_msg}"; then
        exit 0
    fi
}

show_start_notification () {
    local title="`gettext \"Starting the I2P Browser...\"`"
    local body="`gettext \"This may take a while, so please be patient.\"`"
    tails-notify-user "${title}" "${body}" 10000
}

54 55
copy_extra_tbb_prefs () {
    local chroot="${1}"
56 57
    local browser_name="${2}"
    local browser_user="${3}"
58

59
    local tbb_prefs="/etc/tor-browser/profile/preferences"
60
    local browser_prefs_dir="${chroot}/home/${browser_user}/.${browser_name}/profile.default/preferences"
61
    mkdir -p "${browser_prefs_dir}"
62
    # Selectively copy the TBB prefs we want
63
    sed '/\(security\|update\|download\|spell\|noscript\|torbrowser\)/!d' "${tbb_prefs}/0000tails.js" > \
64
                    "${browser_prefs_dir}/0000tails.js"
65
    sed '/\(capability\|noscript\)/!d' "${tbb_prefs}/extension-overrides.js" > \
66
                    "${browser_prefs_dir}/extension-overrides.js"
67
    chown -R "${browser_user}:${browser_user}" "${browser_prefs_dir}"
Kill Your TV's avatar
Kill Your TV committed
68 69 70 71 72 73 74 75
}

show_shutdown_notification () {
    local title="`gettext \"Shutting down the I2P Browser...\"`"
    local body="`gettext \"This may take a while, and you may not restart the I2P Browser until it is properly shut down.\"`"
    tails-notify-user "${title}" "${body}" 10000
}

76 77 78
# Main script:

# This isn't very useful without I2P...
79
i2p_is_enabled || exit 0
80

81
CMD="$(basename "${0}")"
82 83 84 85 86 87
LOCK="/var/lock/${CMD}"
CONF_DIR="/var/lib/i2p-browser"
COW="${CONF_DIR}/cow"
CHROOT="${CONF_DIR}/chroot"
BROWSER_NAME="i2p-browser"
BROWSER_USER="i2pbrowser"
88
HOME_PAGE="http://127.0.0.1:7657"
89 90 91
NOSCRIPT_EXT_XPI="${TBB_EXT}/{73a6fe31-595d-460b-a920-fcc0f8843232}.xpi"
TORBUTTON_EXT_DIR="${TBB_EXT}/torbutton@torproject.org"
HUMAN_READABLE_NAME="`gettext \"I2P Browser\"`"
92
IP4_NAMESERVERS="0.0.0.0"
93

Kill Your TV's avatar
Kill Your TV committed
94
# Prevent multiple instances of the script.
95
exec 9>"${LOCK}"
Kill Your TV's avatar
Kill Your TV committed
96 97 98 99
if ! flock -x -n 9; then
    error "`gettext \"Another I2P Browser is currently running, or being cleaned up. Please retry in a while.\"`"
fi

100
if ! i2p_router_console_is_ready; then
Kill Your TV's avatar
Kill Your TV committed
101 102 103
    verify_start
fi
show_start_notification
104

105
echo "* Setting up chroot"
106
setup_chroot_for_browser "${CHROOT}" "${COW}" "${BROWSER_USER}" || \
107
    error "`gettext \"Failed to setup chroot.\"`"
108

109
echo "* Configuring chroot"
110 111 112 113 114
configure_chroot_browser "${CHROOT}" "${BROWSER_USER}" "${BROWSER_NAME}" \
    "${HUMAN_READABLE_NAME}" "${HOME_PAGE}" "${IP4_NAMESERVERS}" \
    "${TBB_EXT}"/langpack-*.xpi "${NOSCRIPT_EXT_XPI}" "${TORBUTTON_EXT_DIR}" && \
    copy_extra_tbb_prefs "${CHROOT}" "${BROWSER_NAME}" "${BROWSER_USER}" || \
        error "`gettext \"Failed to configure browser.\"`"
115

116
echo "* Starting I2P Browser"
117
run_browser_in_chroot "${CHROOT}" "${BROWSER_NAME}" "${BROWSER_USER}" \
118 119
    "${SUDO_USER}" || \
    error "`gettext \"Failed to run browser.\"`"
120 121

echo "* Exiting the I2P Browser"
Kill Your TV's avatar
Kill Your TV committed
122 123 124
show_shutdown_notification

exit 0