#!/bin/sh
set -e
set -u
. gettext.sh
TEXTDOMAIN="tails"
export TEXTDOMAIN
# Import tor_has_bootstrapped()
. /usr/local/lib/tails-shell-library/systemd.sh
# Import the TBB_EXT variable.
. /usr/local/lib/tails-shell-library/tor-browser.sh
# Import localized_tails_doc_page().
. /usr/local/lib/tails-shell-library/localization.sh
# Import setup_chroot_for_browser(), configure_chroot_browser(),
# and run_browser_in_chroot().
. /usr/local/lib/tails-shell-library/chroot-browser.sh
# Import unsafe_browser_is_enabled
. /usr/local/lib/tails-shell-library/tails-greeter.sh
error () {
local cli_text="${CMD}: `gettext \"error:\"` ${@}"
local dialog_text="`gettext \"Error\"`
${@}"
echo "${cli_text}" >&2
sudo -u "${SUDO_USER}" zenity --error --ellipsize --title "" --text "${dialog_text}"
exit 1
}
verify_start () {
# Make sure the user really wants to start the browser
local dialog_msg="`gettext \"Launch the Unsafe Browser?\"`
`gettext \"The Unsafe Browser is not anonymous and the websites that you visit can see your real IP address.\\n\nOnly use the Unsafe Browser to log in to a captive portal or browse trusted web pages on the local network.\"`"
local launch="`gettext \"_Launch\"`"
local exit="`gettext \"_Exit\"`"
if ! sudo -u "${SUDO_USER}" \
zenity --question --ellipsize --title "" --text "${dialog_msg}" --default-cancel \
--ok-label "${launch}" --cancel-label "${exit}"; then
exit 0
fi
}
show_start_notification () {
local title="`gettext \"Starting the Unsafe Browser...\"`"
local body="`gettext \"This may take a while, so please be patient.\"`"
tails-notify-user "${title}" "${body}" 10000
}
show_shutdown_notification () {
local title="`gettext \"Shutting down the Unsafe Browser...\"`"
local body="`gettext \"This may take a while, and you may not restart the Unsafe Browser until it is properly shut down.\"`"
tails-notify-user "${title}" "${body}" 10000
}
maybe_restart_tor () {
# Restart Tor if it's not working (a captive portal may have prevented
# Tor from bootstrapping, and a restart is the fastest way to get
# wheels turning)
if ! tor_has_bootstrapped; then
echo "* Restarting Tor"
restart-tor
if ! systemctl --quiet is-active tor@default.service; then
error "`gettext \"Failed to restart Tor.\"`"
fi
fi
}
# Main script:
CMD="$(basename "${0}")"
LOCK="/var/lock/${CMD}"
CONF_DIR="/var/lib/unsafe-browser"
COW="${CONF_DIR}/cow"
CHROOT="${CONF_DIR}/chroot"
BROWSER_NAME="unsafe-browser"
BROWSER_USER="clearnet"
HUMAN_READABLE_NAME="`gettext \"Unsafe Browser\"`"
WARNING_PAGE='/usr/share/doc/tails/website/misc/unsafe_browser_warning'
HOME_PAGE="$(localized_tails_doc_page "${WARNING_PAGE}")"
# Check if the Unsafe Browser was disabled in the startup options
if ! unsafe_browser_is_enabled; then
error "`gettext \"The Unsafe Browser was not enabled in the Welcome Screen.\n\n\
To use the Unsafe Browser, restart Tails and enable \
the Unsafe Browser in the additional settings of the Welcome Screen.\n
To always enable the Unsafe Browser, turn on the Welcome Screen feature of the Persistent Storage.\"`"
fi
# Prevent multiple instances of the script.
exec 9>"${LOCK}"
if ! flock -x -n 9; then
error "`gettext \"Another Unsafe Browser is currently running, or being cleaned up. Please retry in a while.\"`"
fi
verify_start
show_start_notification
echo "* Setting up chroot"
setup_chroot_for_browser "${CHROOT}" "${COW}" "${BROWSER_USER}" || \
error "`gettext \"Failed to setup chroot.\"`"
echo "* Configuring chroot"
configure_chroot_browser "${CHROOT}" "${BROWSER_USER}" "${BROWSER_NAME}" \
"${HUMAN_READABLE_NAME}" "${HOME_PAGE}" \
"${TBB_EXT}"/langpack-*.xpi \
/usr/share/tails/chroot-browsers/unsafe-browser/extensions/*.xpi || \
error "`gettext \"Failed to configure browser.\"`"
# If /etc/resolv-over-clearnet.conf file is empty or doesn't exist, we
# have no clearnet DNS server.
if [ "$(stat --format=%s /etc/resolv-over-clearnet.conf || echo 0)" -gt 0 ]; then
mount --bind /etc/resolv-over-clearnet.conf "${CHROOT}"/etc/resolv.conf
else
error "`gettext \"No DNS server was obtained through DHCP or manually configured in NetworkManager.\"`"
fi
echo "* Starting Unsafe Browser"
# Do not localize the 5th argument: it becomes WM_CLASS and then GNOME
# displays the localized app name found in the matching .desktop file;
# if WM_CLASS were localized then not only string encoding problems
# would happen, but GNOME would pick the wrong icon.
run_browser_in_chroot "${CHROOT}" "${BROWSER_NAME}" "${BROWSER_USER}" \
"${SUDO_USER}" \
'Unsafe Browser' || \
error "`gettext \"Failed to run browser.\"`"
echo "* Exiting the Unsafe Browser"
show_shutdown_notification
maybe_restart_tor
exit 0