Commit 364a3c8d authored by anonym's avatar anonym

Avoid set -u issue when testing if variable is set or not.

Whenever there's a risk that we will reference a shell variable in a
script run with `set -u` (including libraries that we sources from
such scripts) we must reference the variable in a way so it gets a
default value, i.e. `${VAR:-}` to give it the empty string as the
default (which is what generally makes sense).

In particular, it's quite clear that in all cases where we do
something like `[ -n "${VAR}" ]` or `[ -z "${VAR}" ]`, where an
expected value is the empty string, which could mean that the variable
is not initialized, we should give such a default (as the empty
string).
parent bbc2d6ca
...@@ -9,7 +9,7 @@ ua="$(unzip -q -p "${TBB_INSTALL}"/browser/omni.ja \ ...@@ -9,7 +9,7 @@ ua="$(unzip -q -p "${TBB_INSTALL}"/browser/omni.ja \
defaults/preferences/000-tor-browser.js | \ defaults/preferences/000-tor-browser.js | \
sed -n 's@^pref("general\.useragent\.override", "\(.*\)");$@\1@p')" sed -n 's@^pref("general\.useragent\.override", "\(.*\)");$@\1@p')"
if [ -z "${ua}" ]; then if [ -z "${ua:-}" ]; then
echo "Got empty user agent string" >&2 echo "Got empty user agent string" >&2
exit 1 exit 1
fi fi
......
...@@ -5,7 +5,7 @@ set -eu ...@@ -5,7 +5,7 @@ set -eu
# Get $XKBMODEL, $XKBLAYOUT, $XKBVARIANT and $XKBOPTIONS # Get $XKBMODEL, $XKBLAYOUT, $XKBVARIANT and $XKBOPTIONS
. /var/lib/tails-user-session/keyboard . /var/lib/tails-user-session/keyboard
if [ -z "$XKBVARIANT" ] ; then if [ -z "${XKBVARIANT:-}" ] ; then
XKBCONF="$XKBLAYOUT" XKBCONF="$XKBLAYOUT"
else else
XKBCONF="$XKBLAYOUT+$XKBVARIANT" XKBCONF="$XKBLAYOUT+$XKBVARIANT"
...@@ -51,7 +51,7 @@ esac ...@@ -51,7 +51,7 @@ esac
# Configure enabled input methods and their preferred order # Configure enabled input methods and their preferred order
dconf write /desktop/ibus/general/preload-engines "$PRELOAD" dconf write /desktop/ibus/general/preload-engines "$PRELOAD"
dconf write /org/gnome/desktop/input-sources/sources "$SOURCES" dconf write /org/gnome/desktop/input-sources/sources "$SOURCES"
if [ -n "$XKBOPTIONS" ] ; then if [ -n "${XKBOPTIONS:-}" ] ; then
dconf write /org/gnome/desktop/input-sources/xkb-options "$XKBOPTIONS" dconf write /org/gnome/desktop/input-sources/xkb-options "$XKBOPTIONS"
fi fi
......
...@@ -125,7 +125,7 @@ configure_chroot_browser_profile () { ...@@ -125,7 +125,7 @@ configure_chroot_browser_profile () {
# Select extensions to enable # Select extensions to enable
local extension local extension
while [ -n "${*}" ]; do while [ -n "${*:-}" ]; do
extension="${1}" ; shift extension="${1}" ; shift
ln -s "${extension}" "${browser_ext}" ln -s "${extension}" "${browser_ext}"
done done
...@@ -138,7 +138,7 @@ configure_chroot_browser_profile () { ...@@ -138,7 +138,7 @@ configure_chroot_browser_profile () {
"${chroot_browser_config}/${browser_name}/prefs.js" > "${browser_prefs}" "${chroot_browser_config}/${browser_name}/prefs.js" > "${browser_prefs}"
# Set browser home page to something that explains what's going on # Set browser home page to something that explains what's going on
if [ -n "${home_page}" ]; then if [ -n "${home_page:-}" ]; then
echo 'user_pref("browser.startup.homepage", "'"${home_page}"'");' >> \ echo 'user_pref("browser.startup.homepage", "'"${home_page}"'");' >> \
"${browser_prefs}" "${browser_prefs}"
fi fi
......
...@@ -48,7 +48,7 @@ guess_best_tor_browser_locale() { ...@@ -48,7 +48,7 @@ guess_best_tor_browser_locale() {
similar_locale="$(ls -1 "${TBB_EXT}" | \ similar_locale="$(ls -1 "${TBB_EXT}" | \
sed -n "s,^langpack-\(${short_locale}-[A-Z]\+\)@firefox.mozilla.org.xpi$,\1,p" | \ sed -n "s,^langpack-\(${short_locale}-[A-Z]\+\)@firefox.mozilla.org.xpi$,\1,p" | \
head -n 1)" || : head -n 1)" || :
if [ -n "${similar_locale}" ]; then if [ -n "${similar_locale:-}" ]; then
echo "${similar_locale}" echo "${similar_locale}"
return return
fi fi
......
...@@ -36,7 +36,7 @@ tor_control_setconf() { ...@@ -36,7 +36,7 @@ tor_control_setconf() {
tor_bootstrap_progress() { tor_bootstrap_progress() {
RES=$(grep -o "\[notice\] Bootstrapped [[:digit:]]\+%:" ${TOR_LOG} | \ RES=$(grep -o "\[notice\] Bootstrapped [[:digit:]]\+%:" ${TOR_LOG} | \
tail -n1 | sed "s|\[notice\] Bootstrapped \([[:digit:]]\+\)%:|\1|") tail -n1 | sed "s|\[notice\] Bootstrapped \([[:digit:]]\+\)%:|\1|")
if [ -z "$RES" ] ; then if [ -z "${RES:-}" ] ; then
RES=0 RES=0
fi fi
echo -n "$RES" echo -n "$RES"
...@@ -55,7 +55,7 @@ tor_is_working() { ...@@ -55,7 +55,7 @@ tor_is_working() {
[ -e $TOR_DESCRIPTORS ] || [ -e $NEW_TOR_DESCRIPTORS ] || return 1 [ -e $TOR_DESCRIPTORS ] || [ -e $NEW_TOR_DESCRIPTORS ] || return 1
TOR_BOOTSTRAP_PROGRESS=$(tor_bootstrap_progress) TOR_BOOTSTRAP_PROGRESS=$(tor_bootstrap_progress)
[ -n "$TOR_BOOTSTRAP_PROGRESS" ] && [ "$TOR_BOOTSTRAP_PROGRESS" -eq 100 ] [ "${TOR_BOOTSTRAP_PROGRESS:-}" -eq 100 ]
} }
tor_append_to_torrc () { tor_append_to_torrc () {
......
...@@ -137,8 +137,8 @@ done ...@@ -137,8 +137,8 @@ done
# MAC spoofing fail-safe: if $NIC's MAC address isn't spoofed at this # MAC spoofing fail-safe: if $NIC's MAC address isn't spoofed at this
# point we have to take some drastic measures in order to prevent # point we have to take some drastic measures in order to prevent
# potential leaks. # potential leaks.
if [ -z "${OLD_MAC}" ] || [ -z "${NEW_MAC}" ] || \ if [ -z "${OLD_MAC:-}" ] || [ -z "${NEW_MAC:-}" ] || \
[ "${OLD_MAC}" = "${NEW_MAC}" ] [ "${OLD_MAC:-}" = "${NEW_MAC:-}" ]
then then
log "Failed to spoof MAC address of NIC ${NIC}. Going into panic mode." log "Failed to spoof MAC address of NIC ${NIC}. Going into panic mode."
if ! mac_spoof_panic "${NIC}"; then if ! mac_spoof_panic "${NIC}"; then
......
...@@ -112,7 +112,7 @@ fi ...@@ -112,7 +112,7 @@ fi
# FIXME: Or would it make sense to fallback to Google's DNS or OpenDNS? # FIXME: Or would it make sense to fallback to Google's DNS or OpenDNS?
# Some stupid captive portals may allow DNS to any host, but chances are # Some stupid captive portals may allow DNS to any host, but chances are
# that only the portal's DNS would forward to the login page. # that only the portal's DNS would forward to the login page.
if [ -z "${IP4_NAMESERVERS}" ]; then if [ -z "${IP4_NAMESERVERS:-}" ]; then
error "`gettext \"No DNS server was obtained through DHCP or manually configured in NetworkManager.\"`" error "`gettext \"No DNS server was obtained through DHCP or manually configured in NetworkManager.\"`"
fi fi
......
...@@ -72,6 +72,6 @@ find "$TOR_TRANSLATION_DIR" -name '*.po' | while read po_file; do ...@@ -72,6 +72,6 @@ find "$TOR_TRANSLATION_DIR" -name '*.po' | while read po_file; do
done done
# Update PO files # Update PO files
if [ -n "$AFTER_IMPORT" ]; then if [ -n "${AFTER_IMPORT:-}" ]; then
eval "$AFTER_IMPORT" eval "$AFTER_IMPORT"
fi fi
...@@ -254,10 +254,10 @@ TARGET_DISPLAY=$(next_free_display) ...@@ -254,10 +254,10 @@ TARGET_DISPLAY=$(next_free_display)
start_xvfb start_xvfb
if [ -n "${VNC_SERVER}" ]; then if [ -n "${VNC_SERVER:-}" ]; then
start_vnc_server start_vnc_server
fi fi
if [ -n "${VNC_VIEWER}" ]; then if [ -n "${VNC_VIEWER:-}" ]; then
start_vnc_viewer start_vnc_viewer
fi fi
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment