various scripts I use to make my life easier
at main 1.1 kB view raw
1#!/bin/bash 2 3# this post-receive hook runs globally on my local git machine 4# if the knot.conf file exists it reads it to get the remote repo and mirror pushes 5# if the file doesn't exist, it doesn't mirror the repo AKA it's private and it stays on my network 6# 7# USAGE: 8# 1) set core.hooksPath to point to where this file is located 9# ex `sudo git --config --system core.hooksPath /home/git/scripts/git-hooks` 10# 2) create a knot.conf file in the repo of your choice with the path to your remote 11# 3) push as normal and everything should mirror 12 13REPO_PATH=$(pwd) 14KNOT_FILE="$REPO_PATH/knot.conf" 15LOGFILE="/home/git/knot-sync.log" #log our syncing isssues 16 17if [ ! -f "$KNOT_FILE" ]; then 18 echo "[$(date)] $REPO_PATH: knot.conf not found, skipping" >> "$LOGFILE" 19 exit 0 20fi 21REPO_URL=$(cat "$KNOT_FILE" | tr -d '\n' | xargs) 22if [ -z "$REPO_URL" ]; then 23 echo "[$(date)] $REPO_PATH: misconfigured knot.conf, skipping" >> "$LOGFILE" 24 exit 0 25fi 26 27echo "[$(date)] BEGIN PUSH $REPO_PATH" >> "$LOGFILE" 28git push --mirror "$REPO_URL" >> "$LOGFILE" 2>&1 29echo "[$(date)] END PUSH $REPO_PATH" >> "$LOGFILE" 30 31# vim: filetype=bash