diff --git a/Partnership/partnership_manager.sh b/Partnership/partnership_manager.sh index de9070b..b5bddda 100755 --- a/Partnership/partnership_manager.sh +++ b/Partnership/partnership_manager.sh @@ -351,16 +351,53 @@ EOF ) 200>"${file}.lock" } +# Deliver the partnership state to the partner, at the path the partner actually reads, under +# both names its UI looks for. +# +# This used to be one scp to "root@ip:$local_file" — the LOCAL absolute path reused verbatim on +# the remote. That only works while both hosts install to the same place. HOST1 is on flash at +# /boot/config/plugins/varaverk and HOST2 is in appdata mode at /mnt/user/appdata/Varaverk, so +# the copy went to a directory HOST2 does not read and, more often, does not have — and the +# failure surfaced as "will propagate on next sync", which nothing does. +# +# Both names, because the page resolves one file per node: partnership_.db. +# The mirror needs partnership_.db for its own card and partnership_.db for the +# owner's. Nothing on the mirror writes the first one during an owner-driven onboard, which is +# why a mirror that was fully onboarded still rendered as having no partnership at all. +# The content is symmetric — state/owner/mirror/onboarded — so one file serves as both. push_state_to_remote() { local local_file="$1" remote_ip="$2" ssh_key="$3" if [[ "$DRY_RUN" == true ]]; then warn "DRY RUN — would push state file to remote" return 0 fi - timeout "$SSH_TIMEOUT" scp -i "$ssh_key" -o ConnectTimeout="$SSH_TIMEOUT" -o BatchMode=yes \ - "$local_file" "root@${remote_ip}:${local_file}" 2>/dev/null && \ - echo "State file pushed to remote ✅" || \ - warn "Could not push state file to remote — will propagate on next sync" + + # Resolve where the partner keeps its state, from the partner. varaverk.cfg names its + # SCRIPTS_DIR; absent it, the flash default is the right guess for a stock install. + local remote_sd remote_state_dir + remote_sd=$(timeout "$SSH_TIMEOUT" ssh -i "$ssh_key" -o ConnectTimeout="$SSH_TIMEOUT" \ + -o BatchMode=yes -o StrictHostKeyChecking=no root@"$remote_ip" \ + 'grep -oP "(?<=SCRIPTS_DIR=\")[^\"]+" /boot/config/plugins/varaverk/varaverk.cfg 2>/dev/null' \ + 2>/dev/null | tr -d '\r') + [[ -z "$remote_sd" ]] && remote_sd="/boot/config/plugins/varaverk" + remote_state_dir="${remote_sd}/data/state" + + local rc=0 + local name + for name in "partnership_${REMOTE_SERVER_NAME}.db" "partnership_${LOCAL_SERVER_NAME}.db"; do + timeout "$SSH_TIMEOUT" ssh -i "$ssh_key" -o ConnectTimeout="$SSH_TIMEOUT" \ + -o BatchMode=yes -o StrictHostKeyChecking=no root@"$remote_ip" \ + "mkdir -p '$remote_state_dir' && cat > '${remote_state_dir}/${name}'" \ + < "$local_file" 2>/dev/null || rc=1 + done + + if [[ $rc -eq 0 ]]; then + echo "State file pushed to $REMOTE_SERVER_NAME:${remote_state_dir} ✅" + return 0 + fi + warn "Could not push state to $REMOTE_SERVER_NAME:${remote_state_dir} — it will keep showing" + warn " no partnership until this succeeds. Nothing retries this on a schedule." + return 1 } read_remote_state() {