From 564229f11b6a6b86a37379a8c6855f5033ce58a2 Mon Sep 17 00:00:00 2001 From: ben Date: Sat, 3 May 2025 15:09:20 -0700 Subject: remote git scripts --- scripts/util/new-repo.sh | 17 +++++++++++++++++ scripts/util/post-receive.sh | 15 +++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 scripts/util/new-repo.sh create mode 100644 scripts/util/post-receive.sh diff --git a/scripts/util/new-repo.sh b/scripts/util/new-repo.sh new file mode 100644 index 0000000..81841b4 --- /dev/null +++ b/scripts/util/new-repo.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +# this is run on remote + +if [ $# -ne 1 ]; then + echo "\nUsage: $0 'new-repo-name'\n" + exit 1 +fi + +echo "\nCreating new bare repository $PWD/$1" + +mkdir "$1" && git init --bare "$1" +chmod -R u+rw "$1"/ +chown -R git:git "$1" + +echo "Adding post-receive hooks\n" +cp /home/git/post-receive.sh "$1"/hooks/post-receive diff --git a/scripts/util/post-receive.sh b/scripts/util/post-receive.sh new file mode 100644 index 0000000..699cce6 --- /dev/null +++ b/scripts/util/post-receive.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# this should be on remote server + +CONF_FILE="/home/git/public_repos.conf" +REPO_NAME=$(basename $(pwd) .git) +PUBLIC_DIR="/var/www/git/$REPO_NAME" + +if grep -qx "$REPO_NAME" "$CONF_FILE"; then + echo "Syncing $REPO_NAME to public directory..." + rsync -a --delete --exclude '.git' /home/git/$REPO_NAME/ "$PUBLIC_DIR/" + echo "Public sync complete." +else + echo "$REPO_NAME is not marked as public. No action taken." +fi -- cgit v1.2.3