Something went wrong. Try again.
Monorepo for Aesthetic.Computer aesthetic.computer
Something went wrong. Try again.
Shell
1234567891011121314151617181920212223242526272829303132333435363738#!/usr/bin/env bash# ac-mirror.sh — bidirectional knot ↔ github mirror for the core repo.# Runs via systemd timer every 60s. Idempotent, exits fast when in sync.set -euo pipefail
REPO=/opt/ac-mirror/coreKNOT_KEY=/root/.ssh/knot_pushGH_KEY=/root/.ssh/github_mirrorBRANCH=main
cd "$REPO"
export GIT_SSH_COMMAND="ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new \ -i $KNOT_KEY -i $GH_KEY"
# "+" prefix → allow non-fast-forward fetches. A mirror must always track# wherever the remote actually is, even after force-pushes or rewinds.git fetch --quiet knot "+$BRANCH":refs/remotes/knot/$BRANCHgit fetch --quiet github "+$BRANCH":refs/remotes/github/$BRANCH
knot_head=$(git rev-parse "knot/$BRANCH")gh_head=$(git rev-parse "github/$BRANCH")
if [ "$knot_head" = "$gh_head" ]; then exit 0fi
if git merge-base --is-ancestor "$gh_head" "$knot_head"; then echo "$(date -Iseconds) → github behind; pushing $knot_head to github." git push --quiet github "$knot_head:refs/heads/$BRANCH"elif git merge-base --is-ancestor "$knot_head" "$gh_head"; then echo "$(date -Iseconds) → knot behind; pushing $gh_head to knot." git push --quiet knot "$gh_head:refs/heads/$BRANCH"else echo "$(date -Iseconds) ⚠️ divergent heads: knot=$knot_head github=$gh_head — skipping (manual resolution required)" >&2 exit 2fi