#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
# shellcheck disable=SC1091
source "${ROOT_DIR}/lib.sh"
load_env_file "${BOOTSTRAP_ENV_FILE:?}"

REPO_DIR="$(repo_dir)"
REPO_ARCHIVE="${KODEX_BOOTSTRAP_REPO_ARCHIVE:?KODEX_BOOTSTRAP_REPO_ARCHIVE is required}"

[ -f "$REPO_ARCHIVE" ] || die "Repository archive not found: $REPO_ARCHIVE"

log "Extract repository archive into active bootstrap repository directory"
rm -rf "$REPO_DIR"
mkdir -p "$REPO_DIR"
tar -xzf "$REPO_ARCHIVE" -C "$REPO_DIR"
