# Validate temporary directory
if [[ -z "$TMPDIR" ]]; then
- echo "WARNING: \"TMPDIR\" is not set, using /tmp as default!" >&2
- TMPDIR='/tmp/'
+ TMPDIR="$(dirname $(mktemp -ut tmp.XXXXXXXXXX))/"
+ echo "WARNING: \"TMPDIR\" is not set, using \"$TMPDIR\" as default!" >&2
fi
if [[ ! -w "$TMPDIR" ]]; then
echo "WARNING: Temporary directory \"$TMPDIR\" is not writable!" >&2
fi
-# Make sure TMPDIR ends in a slash (like on macOS by default): this makes its
-# usage a bit safer ...
-case "$TMPDIR" in
- */) ;;
- *) TMPDIR="$TMPDIR/"
-esac
-export TMPDIR
# Setup XDG cache directory
if [[ -z "$XDG_CACHE_HOME" ]]; then
# Setup XDG runtime directory
if [[ -z "$XDG_RUNTIME_DIR" ]]; then
- XDG_RUNTIME_DIR="${TMPDIR:-/tmp/${UID}-runtime-dir}"
+ XDG_RUNTIME_DIR="$TMPDIR/runtime-dir.$UID"
fi
if [[ ! -d "$XDG_RUNTIME_DIR" ]]; then
mkdir -p "$XDG_RUNTIME_DIR"