#!/bin/bash
# publish patch8 client files: copy staged files into patch_files, regenerate the manifest. Run after deploy-patch8.
set -eu
P=~/heroes_journey_workspace/patcher; S=$P/staged_patch8; B=~/.local/share/eq-backups/$(date -u +%F)/patch8-client
cd $P; [[ $(md5sum patch_files/dbstr_us.txt | cut -c1-32) == bc6a1ccf15a4e45b8487330457718926 && $(md5sum patch_files/spells_us.txt | cut -c1-32) == 27c57c019a942743aa4e0f5fcd0ccced ]] || { echo "patch_files/dbstr_us.txt or spells_us.txt changed since staging (2026-10-06 13:27 UTC): re-append the Call Group lines from ~/eqserver-test/sql/call_group_client_lines.txt onto the current files instead of copying the staged ones"; exit 1; }
mkdir -p $B; cp -p $P/patch_files/dinput8.dll $P/patch_files/dbstr_us.txt $P/patch_files/spells_us.txt $P/patch_manifest.json $P/news.txt $B/
cp -p $S/dinput8.dll $S/dbstr_us.txt $S/spells_us.txt $P/patch_files/
grep -q "Call Group" $P/news.txt || { { 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)"
