#!/bin/bash
# publish patch9 client files: copy the staged dbstr_us.txt (AA "Rank effects:" descriptions) into patch_files,
# prepend the news line, regenerate the manifest. Run after deploy-patch9 (server must already be back up).
set -eu
P=~/heroes_journey_workspace/patcher; S=$P/staged_aadesc; B=~/.local/share/eq-backups/$(date -u +%F)/patch9-client
cd $P
[[ $(md5sum patch_files/dbstr_us.txt | cut -c1-32) == 0976704d7f6779e7cf704a83269275b7 ]] || { echo "patch_files/dbstr_us.txt changed since staging (2026-10-07): re-check Call Group lines 30254^/42705^ are still present, regenerate staged_aadesc/dbstr_us.txt with tools/aa_desc/gen_aa_desc.py against the current file, then re-run"; exit 1; }
mkdir -p $B
cp -p $P/patch_files/dbstr_us.txt $P/patch_manifest.json $P/news.txt $B/
cp -p $S/dbstr_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)"
