#!/bin/bash
# DO NOT RUN until the prod promotion that carries the matching code + SQL (see report). Publishes the Sympathetic tooltip client files:
# copies staged dbstr_us.txt + spells_us.txt into patch_files, prepends the news line, regenerates the manifest.
# Run after the prod deploy (server back up). Guards: the live patch_files copies must be the ones this was built from.
set -eu
P=~/heroes_journey_workspace/patcher; S=$P/staged_sympathetic; B=~/.local/share/eq-backups/$(date -u +%F)/sympathetic-client
cd $P
[[ $(md5sum patch_files/dbstr_us.txt  | cut -c1-32) == 32bcb9081273f124f1fb35bc7e842114 ]] || { echo "patch_files/dbstr_us.txt changed since staging (2026-10-25): rebuild with staged_sympathetic/build.py against the current file"; exit 1; }
[[ $(md5sum patch_files/spells_us.txt | cut -c1-32) == 042eb514b17e40c9740e9e5a662e496a ]] || { echo "patch_files/spells_us.txt changed since staging (2026-10-25): rebuild with staged_sympathetic/build.py against the current file"; exit 1; }
mkdir -p $B
cp -p $P/patch_files/dbstr_us.txt $P/patch_files/spells_us.txt $P/patch_manifest.json $P/news.txt $B/
cp -p $S/dbstr_us.txt $S/spells_us.txt $P/patch_files/
{ cat $S/news_line.txt; cat $P/news.txt; } > $P/news.txt.new && mv $P/news.txt.new $P/news.txt
cd $P && python3 generate_manifest.py && grep -c '"' patch_manifest.json >/dev/null && echo "published: $(date -u)"
