site
scripts to generate personal blog and git repositories
git clone https://9o.is/git/site.git
post-receive.sample
(783B)
1 #!/bin/sh
2 set -eu
3
4 # Place this in bare repo's hooks/post-receive as executable.
5 # Manually set REPO variable and additional make targets if necessary.
6
7 TARGET="REPO={{REPO}} sync-stagit"
8
9 SITE_DIR=/home/user/site
10 BUILD_DIR=/tmp/git-site-build
11 LOCKFILE=$BUILD_DIR.lock
12
13 read oldrev newrev refname
14
15 if [ "$refname" != 'refs/heads/main' ]; then
16 echo "Push received for $refname. Skipping build (only 'main' triggers build)."
17 exit 0
18 fi
19
20 (
21 echo "--- Acquiring Lock for $newrev ---"
22 flock -x 200 || exit 1
23 echo "--- Starting Build for $newrev ---"
24
25 rm -rf "$BUILD_DIR" && mkdir -p "$BUILD_DIR"
26 git --work-tree="$BUILD_DIR" --git-dir="$SITE_DIR" checkout -f main
27 cd "$BUILD_DIR" || exit
28 make $TARGET
29
30 echo "--- Build Complete ---"
31 ) 200>"$LOCKFILE"