diff options
| author | Trey Bastian <hello@treybastian.com> | 2025-10-28 11:31:58 +0000 |
|---|---|---|
| committer | Trey Bastian <hello@treybastian.com> | 2025-10-28 11:31:58 +0000 |
| commit | 839c8c87267aa43e592aebb7532ffec661836370 (patch) | |
| tree | 41ccd5fb603fb0fe91c2770d88dba6e2c112aab3 | |
| parent | 19474eeaae68c6063e322bd361285589dc857de1 (diff) | |
added usage instructions and relocated git-hooks
| -rw-r--r-- | README.md | 6 | ||||
| -rwxr-xr-x | git-hooks/post-receive | 31 | ||||
| -rw-r--r-- | post-receive | 24 |
3 files changed, 36 insertions, 25 deletions
@@ -1,2 +1,6 @@ -my scripts +# My Scripts + +These are a collection of scripts I use to make my life easier. + +Every script has documentation for what they do and how to use them. diff --git a/git-hooks/post-receive b/git-hooks/post-receive new file mode 100755 index 0000000..6445e0b --- /dev/null +++ b/git-hooks/post-receive @@ -0,0 +1,31 @@ +#!/bin/bash + +# this post-receive hook runs globally on my local git machine +# if the knot.conf file exists it reads it to get the remote repo and mirror pushes +# if the file doesn't exist, it doesn't mirror the repo AKA it's private and it stays on my network +# +# USAGE: +# 1) set core.hooksPath to point to where this file is located +# ex `sudo git --config --system core.hooksPath /home/git/scripts/git-hooks` +# 2) create a knot.conf file in the repo of your choice with the path to your remote +# 3) push as normal and everything should mirror + +REPO_PATH=$(pwd) +KNOT_FILE="$REPO_PATH/knot.conf" +LOGFILE="/home/git/knot-sync.log" #log our syncing isssues + +if [ ! -f "$KNOT_FILE" ]; then + echo "[$(date)] $REPO_PATH: knot.conf not found, skipping" >> "$LOGFILE" + 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 + +echo "[$(date)] BEGIN PUSH $REPO_PATH" >> "$LOGFILE" +git push --mirror "$REPO_URL" >> "$LOGFILE" 2>&1 +echo "[$(date)] END PUSH $REPO_PATH" >> "$LOGFILE" + +# vim: filetype=sh diff --git a/post-receive b/post-receive deleted file mode 100644 index 458162b..0000000 --- a/post-receive +++ /dev/null @@ -1,24 +0,0 @@ -#!/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="/home/git/knot-sync.log" #log our syncing isssues - -if [ ! -f "$KNOT_FILE" ]; then - echo "[$(date)] $REPO_PATH: knot.conf not found, skipping" >> "$LOGFILE" - 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 - -echo "syncing $REPO_PATH" >> "$LOGFILE" -git push --mirror "$REPO_URL" >> "$LOGFILE" 2>&1 - -# vim: filetype=sh |
