i2p-browser 5.58 KB
Newer Older
Kill Your TV's avatar
Kill Your TV committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/bin/sh

set -e

# 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

15 16
. /usr/local/lib/tails-shell-library/i2p.sh

Kill Your TV's avatar
Kill Your TV committed
17 18 19 20
CONF_DIR=/var/lib/i2p-browser
COW=${CONF_DIR}/cow
CHROOT=${CONF_DIR}/chroot
BROWSER_USER=i2pbrowser
21
TBB_PREFS="/etc/tor-browser/profile/preferences"
Kill Your TV's avatar
Kill Your TV committed
22 23
START_PAGE="http://127.0.0.1:7657"

24 25 26
# Import the TBB_INSTALL, TBB_EXT and TBB_PROFILE variables, and
# exec_firefox(), configure_xulrunner_app_locale() and
# guess_best_tor_browser_locale()
27 28
. /usr/local/lib/tails-shell-library/tor-browser.sh

29 30
. /usr/local/lib/tails-shell-library/chroot-browser.sh

Tails developers's avatar
Tails developers committed
31 32
NOSCRIPT_EXT_XPI="${TBB_EXT}/{73a6fe31-595d-460b-a920-fcc0f8843232}.xpi"
TORBUTTON_EXT_DIR="${TBB_EXT}/torbutton@torproject.org"
Kill Your TV's avatar
Kill Your TV committed
33
NAME="`gettext \"I2P Browser\"`"
34

Kill Your TV's avatar
Kill Your TV committed
35 36 37 38 39
if [ -e /var/lib/gdm3/tails.camouflage ]; then
    CAMOUFLAGE=yes
fi

cleanup () {
40
    try_cleanup_browser_chroot ${CHROOT} ${COW} ${BROWSER_USER}
Kill Your TV's avatar
Kill Your TV committed
41 42
}

43 44 45 46 47 48 49 50 51 52
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
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
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
}

configure_chroot () {
    # Prevent sudo from complaining about failing to resolve the 'amnesia' host
    echo "127.0.0.1 localhost amnesia" > ${CHROOT}/etc/hosts

78
    # Create a fresh Tor Browser profile for the i2pbrowser user
79 80
    BROWSER_CONF="${CHROOT}/home/${BROWSER_USER}/.tor-browser"
    BROWSER_PROFILE="${BROWSER_CONF}/profile.default"
81 82
    BROWSER_EXT="${BROWSER_PROFILE}/extensions"
    mkdir -p "${BROWSER_EXT}"
Tails developers's avatar
Tails developers committed
83 84
    ln -s "${NOSCRIPT_EXT_XPI}" "${BROWSER_EXT}"
    ln -s "${TORBUTTON_EXT_DIR}" "${BROWSER_EXT}"
Kill Your TV's avatar
Kill Your TV committed
85
    for LANGPACK in $(ls ${TBB_PROFILE}/extensions/langpack-*.xpi); do
Kill Your TV's avatar
Kill Your TV committed
86 87
        ln -s "${LANGPACK}" "${BROWSER_EXT}"
    done
88

89 90 91 92 93
    BROWSER_PREF_DIR="${BROWSER_PROFILE}/preferences"
    BROWSER_PREFS="${BROWSER_PREF_DIR}/prefs.js"
    mkdir -p "${BROWSER_PREF_DIR}"

    # Selectively copy the TBB prefs we want
94 95
    sed '/\(security\|update\|download\|spell\|noscript\|torbrowser\|torbutton\)/!d' $TBB_PREFS/0000tails.js > \
                    ${BROWSER_PREF_DIR}/0000tails.js
Kill Your TV's avatar
Kill Your TV committed
96
    sed '/\(capability\|noscript\|torbutton\)/!d' ${TBB_PREFS}/extension-overrides.js > \
97 98 99
                    ${BROWSER_PREF_DIR}/extension-overrides.js

    # Localization
100 101
    BEST_LOCALE="$(guess_best_tor_browser_locale)"
    configure_xulrunner_app_locale "${BROWSER_PROFILE}" "${BEST_LOCALE}"
102

103
    # Set the name (e.g. window title) of the browser
104
    set_chroot_torbutton_browser_name "${CHROOT}" "${NAME}" "${BEST_LOCALE}"
105 106 107 108 109

    # Set start page to the router console
    echo 'user_pref("browser.startup.homepage", "'${START_PAGE}'");' >> \
        ${BROWSER_PREFS}

Kill Your TV's avatar
Kill Your TV committed
110
    # add the I2P proxy to all protocols
111 112
    cp /usr/share/tails/i2p-browser/i2p-browser.js "${BROWSER_PREF_DIR}"

113
    # Hide options in the I2P Browser.
Kill Your TV's avatar
Kill Your TV committed
114
    # It would be good to implement the ability to persist the browser profile in the
115 116 117
    # future. At that point, the Bookmark functionality could be restored.
    BROWSER_CHROME="${BROWSER_PROFILE}/chrome/userChrome.css"
    mkdir -p "$(dirname "${BROWSER_CHROME}")"
118
    cp /usr/share/tails/i2p-browser/userChrome.css ${BROWSER_CHROME}
Kill Your TV's avatar
Kill Your TV committed
119

120 121 122 123 124
    # Remove all bookmarks
    rm -f "${CHROOT}/${TBB_PROFILE}/bookmarks.html"
    rm -f ${BROWSER_PROFILE}/bookmarks.html
    rm -f ${BROWSER_PROFILE}/places.sqlite

Tails developers's avatar
Tails developers committed
125
    chown -R ${BROWSER_USER}:${BROWSER_USER} "${BROWSER_CONF}"
126

Kill Your TV's avatar
Kill Your TV committed
127 128
    # Change the theme when not using Windows camouflage
    if [ -z "${CAMOUFLAGE}" ]; then
129
        cat /usr/share/tails/i2p-browser/i2p-browser-theme.js >> "${BROWSER_PREFS}"
Kill Your TV's avatar
Kill Your TV committed
130 131 132
    else
        # The camouflage activation script requires a dbus server for
        # properly configuring GNOME, so we start one in the chroot
133
        chroot ${CHROOT} sudo -H -u ${BROWSER_USER} sh -c 'eval `dbus-launch --auto-syntax`; tails-activate-win8-theme' || :
Kill Your TV's avatar
Kill Your TV committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
    fi

}

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
}

# 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

150
if ! i2p_router_console_is_ready; then
Kill Your TV's avatar
Kill Your TV committed
151 152 153
    verify_start
fi
show_start_notification
154 155 156
echo "* Setting up chroot"
setup_browser_chroot ${CHROOT} ${COW} || \
    error "`gettext \"Failed to setup chroot.\"`"
157
echo "* Configuring chroot"
Kill Your TV's avatar
Kill Your TV committed
158
configure_chroot
159 160
echo "* Starting I2P Browser"
run_chroot_browser ${CHROOT} ${BROWSER_USER} ${SUDO_USER}
Kill Your TV's avatar
Kill Your TV committed
161 162 163
show_shutdown_notification

exit 0