#!/bin/sh

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

## Must be an sh, not bash script, because /etc/cron.weekly/tor is a sh script,
## that sources /etc/default/tor, which sources this script.

## Cope up with "set -o nounset".
: "${DEBDEBUG:="0"}"
: "${LD_PRELOAD:=""}"

if [ "$DEBDEBUG" = "1" ]; then
   set -x
fi

if [ "$DEBDEBUG" = "1" ]; then
   true "LD_PRELOAD: $LD_PRELOAD"
fi

## Remove /usr/lib/torsocks/libtorsocks.so from LD_PRELOAD.
LD_PRELOAD="$(printf '%s' "$LD_PRELOAD" | sed 's|/usr/lib/torsocks/libtorsocks.so||g')"

if [ "$DEBDEBUG" = "1" ]; then
   true "exit code: $?"
fi

export LD_PRELOAD

if [ "$DEBDEBUG" = "1" ]; then
   true "exit code: $?"

   true "LD_PRELOAD: $LD_PRELOAD"
fi

## Don't use exit at the end, since this script can be sourced by others.
