#!/usr/bin/env bash set -euo pipefail if [[ "$#" -ne 1 ]]; then echo "usage: journal-sync.sh journals/YYYY_MM_DD.md" >&2 exit 64 fi rel="$1" if [[ ! "$rel" =~ ^journals/[0-9]{4}_[0-9]{2}_[0-9]{2}\.md$ ]]; then echo "refusing non-journal path: $rel" >&2 exit 65 fi vault="${PI_MEMO_VAULT:-$HOME/obsidian-vault}" lock="$HOME/.local/state/obsidian-sync/git-sync.lock" mkdir -p "$(dirname "$lock")" exec 9>"$lock" flock -w 30 9 cd "$vault" git add -- "$rel" if git diff --cached --quiet -- "$rel"; then echo "no journal changes to commit" exit 0 fi git commit -m "journal: Pi Memo $(date +%Y-%m-%d-%H%M)" -- "$rel" # The host's system SSH config may be managed outside this service. Keep the # memo sync self-contained so unrelated ownership errors cannot block pushes. export GIT_SSH_COMMAND="ssh -F $HOME/.ssh/config -i $HOME/.ssh/id_ed25519_gitea -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new" if ! git push origin main; then git pull --rebase origin main git push origin main fi echo "pushed $(git rev-parse --short HEAD)"