#!/usr/bin/env bash

MODULE_FTP_SERVER_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$MODULE_FTP_SERVER_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=core/runtime.sh
source "$PROJECT_ROOT/core/runtime.sh"
# shellcheck source=modules/network/ftp-server/module.sh
source "$MODULE_FTP_SERVER_DIR/module.sh"

runtime_init "$PROJECT_ROOT"
log_init

if ! test -f "$PROJECT_ROOT/config/ftp-server.yaml"; then
  printf 'ftp-server test FAILED: missing repository config\n' >&2
  exit 1
fi

if ! package_is_installed vsftpd; then
  printf 'ftp-server test SKIPPED: vsftpd not installed\n'
  exit 0
fi

if module_ftp_server_test; then
  printf 'ftp-server test OK\n'
else
  printf 'ftp-server test FAILED\n' >&2
  exit 1
fi
