#!/bin/bash set -e # Enable/disable the git-sync plugin by flipping `enabled:` in its config. # # git-sync.yaml may live in the per-environment config tree # (user/env//config/plugins/) when an env override dir exists — Grav's # Admin saves config there when an environment is active — otherwise in the # standard user/config/plugins/. Search both, env path first. WEBROOT="$1" STATE="$2" : "${WEBROOT:?usage: git-sync-toggle.sh }" : "${STATE:?usage: git-sync-toggle.sh }" FILE=$(ls "$WEBROOT"/user/env/*/config/plugins/git-sync.yaml \ "$WEBROOT"/user/config/plugins/git-sync.yaml 2>/dev/null | head -1) if [ -z "$FILE" ] || [ ! -f "$FILE" ]; then echo "ERROR: git-sync.yaml not found under $WEBROOT — is git-sync installed/configured?" >&2 exit 1 fi if grep -qE '^enabled:' "$FILE"; then sed -i -E "s/^enabled:.*/enabled: ${STATE}/" "$FILE" else printf 'enabled: %s\n' "$STATE" | cat - "$FILE" > "$FILE.tmp" && mv "$FILE.tmp" "$FILE" fi echo "git-sync now: $(grep -E '^enabled:' "$FILE") ($FILE)"