#!/bin/bash
# shellcheck disable=SC1090
# this is for backward compatibility and also because it
# is more convenient for the admin to have the script at
# the top level of the SecureDrop repository
set -eo pipefail

b=$(basename "$0")
u=$(whoami)
if test "$u" = "root"; then
    echo "Please do not run \"$b\" directly as root."
    exit 1
fi

d=$(dirname "$0")
if test "$1" = "setup" || test "$2" = "setup"; then
   if test "$1" = "setup"; then
     shift
     exec python3 "$d/admin/bootstrap.py" "$@"
   else
     exec python3 "$d/admin/bootstrap.py" "$1"
   fi
else
   python3 "$d/admin/bootstrap.py" "checkenv"
   source "$d/admin/.venv3/bin/activate"
   exec "$d/admin/.venv3/bin/securedrop-admin" --root "$d" "$@"
fi
