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 \
defaults/preferences/000-tor-browser.js | \
sed -n 's@^pref("general\.useragent\.override", "\(.*\)");$@\1@p')"
if [ -z "${ua}" ]; then
if [ -z "${ua:-}" ]; then
echo "Got empty user agent string" >&2
exit 1
fi
......
......@@ -5,7 +5,7 @@ set -eu
# Get $XKBMODEL, $XKBLAYOUT, $XKBVARIANT and $XKBOPTIONS
. /var/lib/tails-user-session/keyboard
if [ -z "$XKBVARIANT" ] ; then
if [ -z "${XKBVARIANT:-}" ] ; then
XKBCONF="$XKBLAYOUT"
else
XKBCONF="$XKBLAYOUT+$XKBVARIANT"
......@@ -51,7 +51,7 @@ esac
# Configure enabled input methods and their preferred order
dconf write /desktop/ibus/general/preload-engines "$PRELOAD"
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"
fi
......
......@@ -125,7 +125,7 @@ configure_chroot_browser_profile () {
# Select extensions to enable
local extension
while [ -n "${*}" ]; do
while [ -n "${*:-}" ]; do
extension="${1}" ; shift
ln -s "${extension}" "${browser_ext}"
done
......@@ -138,7 +138,7 @@ configure_chroot_browser_profile () {
"${chroot_browser_config}/${browser_name}/prefs.js" > "${browser_prefs}"
# 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}"'");' >> \
"${browser_prefs}"
fi
......
......@@ -48,7 +48,7 @@ guess_best_tor_browser_locale() {
similar_locale="$(ls -1 "${TBB_EXT}" | \
sed -n "s,^langpack-\(${short_locale}-[A-Z]\+\)@firefox.mozilla.org.xpi$,\1,p" | \
head -n 1)" || :
if [ -n "${similar_locale}" ]; then
if [ -n "${similar_locale:-}" ]; then
echo "${similar_locale}"
return
fi
......
......@@ -36,7 +36,7 @@ tor_control_setconf() {
tor_bootstrap_progress() {
RES=$(grep -o "\[notice\] Bootstrapped [[:digit:]]\+%:" ${TOR_LOG} | \
tail -n1 | sed "s|\[notice\] Bootstrapped \([[:digit:]]\+\)%:|\1|")
if [ -z "$RES" ] ; then
if [ -z "${RES:-}" ] ; then
RES=0
fi
echo -n "$RES"
......@@ -55,7 +55,7 @@ tor_is_working() {
[ -e $TOR_DESCRIPTORS ] || [ -e $NEW_TOR_DESCRIPTORS ] || return 1
TOR_BOOTSTRAP_PROGRESS=$(tor_bootstrap_progress)
[ -n "$TOR_BOOTSTRAP_PROGRESS" ] && [ "$TOR_BOOTSTRAP_PROGRESS" -eq 100 ]
[ "${TOR_BOOTSTRAP_PROGRESS:-}" -eq 100 ]
}
tor_append_to_torrc () {
......
......@@ -137,8 +137,8 @@ done
# 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
# potential leaks.
if [ -z "${OLD_MAC}" ] || [ -z "${NEW_MAC}" ] || \
[ "${OLD_MAC}" = "${NEW_MAC}" ]
if [ -z "${OLD_MAC:-}" ] || [ -z "${NEW_MAC:-}" ] || \
[ "${OLD_MAC:-}" = "${NEW_MAC:-}" ]
then
log "Failed to spoof MAC address of NIC ${NIC}. Going into panic mode."
if ! mac_spoof_panic "${NIC}"; then
......
......@@ -112,7 +112,7 @@ fi
# 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
# 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.\"`"
fi
......
......@@ -72,6 +72,6 @@ find "$TOR_TRANSLATION_DIR" -name '*.po' | while read po_file; do
done
# Update PO files
if [ -n "$AFTER_IMPORT" ]; then
if [ -n "${AFTER_IMPORT:-}" ]; then
eval "$AFTER_IMPORT"
fi
......@@ -254,10 +254,10 @@ TARGET_DISPLAY=$(next_free_display)
start_xvfb
if [ -n "${VNC_SERVER}" ]; then
if [ -n "${VNC_SERVER:-}" ]; then
start_vnc_server
fi
if [ -n "${VNC_VIEWER}" ]; then
if [ -n "${VNC_VIEWER:-}" ]; then
start_vnc_viewer
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