#!/bin/bash
# DO NOT RUN until Fabled 2.0 epics are promoted to prod (sql/2026-10-26_fabled_epics.sql applied to Biggsvr + quests
# + restart). Publishes the client spell rows 43100-43140 and their descriptions: copies staged spells_us.txt +
# dbstr_us.txt into patch_files and regenerates the manifest. No news line (add one by hand if wanted).
# Built on top of staged_sympathetic/ (what the 2026-10-26 08:15 UTC patcher update publishes): the guards below
# refuse to run unless patch_files holds exactly those files.
set -eu
P=~/heroes_journey_workspace/patcher; S=$P/staged_fabled_epics; B=~/.local/share/eq-backups/$(date -u +%F)/fabled-epics-client
cd $P
[[ $(md5sum patch_files/spells_us.txt | cut -c1-32) == b75f0646f3b9a4fb2314c5d5a18f644a ]] || { echo "patch_files/spells_us.txt is not the staged_sympathetic build: rebuild with staged_fabled_epics/tools/stage.py against the current file"; exit 1; }
[[ $(md5sum patch_files/dbstr_us.txt  | cut -c1-32) == ac8c55c5cb64044d468b6c597392cdbe ]] || { echo "patch_files/dbstr_us.txt is not the staged_sympathetic build: rebuild with staged_fabled_epics/tools/stage.py against the current file"; exit 1; }
[[ $(md5sum $S/spells_us.txt | cut -c1-32) == 6cb2d6020a317acc5fed1edf12ed4e20 ]] || { echo "staged spells_us.txt changed"; exit 1; }
[[ $(md5sum $S/dbstr_us.txt  | cut -c1-32) == b9b81792ce7e576a7b992045eb195754 ]] || { echo "staged dbstr_us.txt changed"; exit 1; }
mkdir -p $B
cp -p $P/patch_files/dbstr_us.txt $P/patch_files/spells_us.txt $P/patch_manifest.json $B/
cp -p $S/dbstr_us.txt $S/spells_us.txt $P/patch_files/
cd $P && python3 generate_manifest.py && grep -c '"' patch_manifest.json >/dev/null && echo "published: $(date -u) (backup in $B)"
