#!/bin/sh
set -e

if [[ $EUID -eq 0 ]]; then
    export ONIONR_HOME=${ONIONR_HOME:-/var/lib/onionr}
    export LOG_DIR=${LOG_DIR:-/var/log/onionr}
else
    export ONIONR_HOME=${ONIONR_HOME:-${XDG_DATA_HOME:-$HOME/.local/share}/onionr}
    export LOG_DIR=${LOG_DIR:-$ONIONR_HOME/logs}
fi

mkdir -p "$ONIONR_HOME" "$LOG_DIR"

chmod 0700 "$ONIONR_HOME" "$LOG_DIR"

exec ${ONIONR_BASEDIR:-/usr/share/onionr}/onionr.sh "$@"
