#!/usr/bin/env bash

MODULE_USER_SUDO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$MODULE_USER_SUDO_DIR/../../.." && pwd)"

# shellcheck source=lib/ui.sh
source "$PROJECT_ROOT/lib/ui.sh"
# shellcheck source=lib/log.sh
source "$PROJECT_ROOT/lib/log.sh"
# shellcheck source=lib/package.sh
source "$PROJECT_ROOT/lib/package.sh"
# shellcheck source=lib/system.sh
source "$PROJECT_ROOT/lib/system.sh"
# shellcheck source=core/runtime.sh
source "$PROJECT_ROOT/core/runtime.sh"
# shellcheck source=modules/system/user-sudo/module.sh
source "$MODULE_USER_SUDO_DIR/module.sh"

runtime_init "$PROJECT_ROOT"
log_init

if ! package_is_installed sudo; then
  printf 'user-sudo test SKIPPED: sudo package not installed\n'
  exit 0
fi

if module_user_sudo_test "${1:-gilles}"; then
  printf 'user-sudo test OK\n'
else
  printf 'user-sudo test FAILED\n' >&2
  exit 1
fi
