#!/usr/bin/env bash

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

runtime_init "$PROJECT_ROOT"
log_init

if ! test -f /etc/postinstall-debian/network-ip-config.conf; then
  printf 'network-ip-config test SKIPPED: module configuration not applied\n'
  exit 0
fi

if module_ip_config_test; then
  printf 'network-ip-config test OK\n'
else
  printf 'network-ip-config test FAILED\n' >&2
  exit 1
fi
