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

set -e

5
# Import the TBB_EXT variable, and guess_best_tor_browser_locale().
6 7
. /usr/local/lib/tails-shell-library/tor-browser.sh

8 9 10
# Import windows_camouflage_is_enabled()
. /usr/local/lib/tails-shell-library/tor-browser.sh

11
. /usr/local/lib/tails-shell-library/chroot-browser.sh
12
. /usr/local/lib/tails-shell-library/i2p.sh
13

Kill Your TV's avatar
Kill Your TV committed
14
cleanup () {
15
    try_cleanup_browser_chroot ${CHROOT} ${COW} ${BROWSER_USER}
Kill Your TV's avatar
Kill Your TV committed
16 17
}

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

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

Kill Your TV's avatar
Kill Your TV committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
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.
    if sudo -u ${SUDO_USER} zenity --question --title "" --ok-label "${exit}" \
       --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
}

49 50 51
copy_extra_tbb_prefs () {
    local chroot="${1}"
    local browser_user="${2}"
52

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

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
}

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
# Main script:

# This isn't very useful without I2P...
grep -qw "i2p" /proc/cmdline || exit 0

CMD=$(basename ${0})
LOCK=/var/lock/${CMD}

. gettext.sh
TEXTDOMAIN="tails"
export TEXTDOMAIN

CONF_DIR=/var/lib/i2p-browser
COW=${CONF_DIR}/cow
CHROOT=${CONF_DIR}/chroot
BROWSER_NAME=i2p-browser
BROWSER_USER=i2pbrowser
START_PAGE="http://127.0.0.1:7657"
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\"`"
BEST_LOCALE="$(guess_best_tor_browser_locale)"

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

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

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

108
echo "* Configuring chroot"
109 110
configure_chroot_dns_servers "${CHROOT}" "127.0.0.1"
configure_chroot_browser "${CHROOT}" "${BROWSER_NAME}" "${BROWSER_USER}" \
111
    "${START_PAGE}" "${TBB_EXT}"/langpack-*.xpi \
112 113 114 115 116 117
    "${NOSCRIPT_EXT_XPI}" "${TORBUTTON_EXT_DIR}"
copy_extra_tbb_prefs "${CHROOT}" "${BROWSER_USER}"
set_chroot_browser_locale "${CHROOT}" "${BROWSER_USER}" "${BEST_LOCALE}"
set_chroot_torbutton_browser_name "${CHROOT}" "${HUMAN_READABLE_NAME}" "${BEST_LOCALE}"
set_chroot_browser_permissions "${CHROOT}" "${BROWSER_USER}"

118 119
echo "* Starting I2P Browser"
run_chroot_browser ${CHROOT} ${BROWSER_USER} ${SUDO_USER}
Kill Your TV's avatar
Kill Your TV committed
120 121 122
show_shutdown_notification

exit 0