#!/bin/bash
# Deploys the SPP overlay (bot data, configs, chat handlers, seeds) and the built jars
# into a server directory (default: ../server). The datapack itself is vanilla Mobius,
# only the files under src_mobius/.../dist are ours.
# Usage: tools/deploy.sh [server_dir] [GameServer.jar]
set -e
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
SRC="$ROOT/src_mobius/mobius/L2J_Mobius_CT_0_Interlude"
TARGET="${1:-$ROOT/server}"
JAR="${2:-$ROOT/src_mobius/mobius/build/dist/libs/GameServer.jar}"
if [ ! -d "$TARGET/game" ]; then
    echo "server dir not found: $TARGET" >&2
    exit 1
fi
# Overlay: everything under dist except libs (vendored build deps) and the ini files that
# the docker entrypoint patches in place (Database.ini / Server.ini are not in the overlay anyway).
rsync -a --no-perms --no-owner --no-group --exclude 'libs/' "$SRC/dist/" "$TARGET/"
if [ -f "$JAR" ]; then
    cp -f "$JAR" "$TARGET/libs/GameServer.jar"
    LOGIN="$(dirname "$JAR")/LoginServer.jar"
    [ -f "$LOGIN" ] && cp -f "$LOGIN" "$TARGET/libs/LoginServer.jar"
    echo "jars -> $TARGET/libs"
else
    echo "no jar at $JAR (build first: tools/build.sh); overlay deployed only"
fi
echo "overlay -> $TARGET (data, config, scripts, sql seeds)"
