aboutsummaryrefslogtreecommitdiff
path: root/post-receive
blob: e2aeb04e68dfc75f7c988bcf2e94c7fa44d041b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/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

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