diff options
| author | Trey Bastian <hello@treybastian.com> | 2025-10-28 09:53:16 +0000 |
|---|---|---|
| committer | Trey Bastian <hello@treybastian.com> | 2025-10-28 09:53:16 +0000 |
| commit | f9ea6343576e435ddd92568c107609993e78d2ee (patch) | |
| tree | 9c94bb0efa5405b2162ce2eafe334cc95bc10404 /post-recieve | |
post-recieve script to mirror public repos
Diffstat (limited to 'post-recieve')
| -rw-r--r-- | post-recieve | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/post-recieve b/post-recieve new file mode 100644 index 0000000..3431765 --- /dev/null +++ b/post-recieve @@ -0,0 +1,27 @@ +#!/bin/bash + +# this post-recieve hook runs globally on my local git machine +# it checks for the precense of a knot.conf file +# if the file exists it reads it to get the remote repo and mirror pushes + + +REPO_PATH=$(pwd) +KNOT_FILE="$REPO_PATH/knot.conf" +LOGFILE="/var/log/knot-sync.log" #log our syncing isssues + +if [ ! -f "$KNOT_FILE" ]; then + exit 0 +fi +REPO_URL=$(cat "$KNOT_FILE" | tr -d '\n' | xargs) +if [ -z "$REPO_URL" ]; then + echo "[$(date)] $REPO_PATH: misconfigured knot.conf, skipping", >> "$LOGFILE" + exit 0 +fi + +sync_repo() { + git push --mirror "$REPO_URL" >> "$LOGFILE" 2>&1 +} + +# make sure the sync occurs in the background +nohup bash -c "sync_repo" > /dev/null 2>&1 & +# vim: filetype=sh |
