diff options
| author | Trey Bastian <hello@treybastian.com> | 2026-04-08 14:36:22 +0100 |
|---|---|---|
| committer | Trey Bastian <hello@treybastian.com> | 2026-04-08 14:36:22 +0100 |
| commit | 97c6c6b7823d9d713f836f967fd10cc3facc36ac (patch) | |
| tree | 55b660d91298ed39e72dcfec050d3a3c879618c3 | |
| parent | 4d82c0a3f2fbf2fdaf379d087a66421a9053c1b5 (diff) | |
updated scripts to slightly new workflow
| -rwxr-xr-x | git-hooks/hook-runner | 6 | ||||
| -rwxr-xr-x | git-hooks/post-receive | 31 | ||||
| -rwxr-xr-x | git-shell-commands/new-project | 33 | ||||
| -rwxr-xr-x | git-shell-commands/new-repo | 24 |
4 files changed, 61 insertions, 33 deletions
diff --git a/git-hooks/hook-runner b/git-hooks/hook-runner index a13e00c..0b69027 100755 --- a/git-hooks/hook-runner +++ b/git-hooks/hook-runner @@ -5,9 +5,9 @@ # symlink this file to all missing hook scripts HOOK_NAME=$(basename "$0") -REPO_HOOK="$(git rev-parse --git-dir)/hooks/$HOOK_NAME" +REPO_HOOK="$(pwd)/hooks/$HOOK_NAME" -if [ -x "$REPO_HOOK"]; then - "$REPO_HOOK" +if [ -x "$REPO_HOOK" ]; then + "$REPO_HOOK" "$@" fi # vim: filetype=bash diff --git a/git-hooks/post-receive b/git-hooks/post-receive index 3f47457..a628d02 100755 --- a/git-hooks/post-receive +++ b/git-hooks/post-receive @@ -6,26 +6,31 @@ # # 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` +# ex `sudo git config --system core.hooksPath /home/git/scripts/git-hooks` # 2) create a public.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) PUBLIC_FILE="$REPO_PATH/public.conf" -LOGFILE="/home/git/public-sync.log" #log our syncing isssues +LOGFILE="/home/git/public-sync.log" # log our syncing isssues -if [ ! -f "$KNOT_FILE" ]; then - echo "[$(date)] $REPO_PATH: public.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 public.conf, skipping" >> "$LOGFILE" - exit 0 +if [ -f "$PUBLIC_FILE" ]; then + REPO_URL=$(cat "$PUBLIC_FILE" | tr -d '\n' | xargs) + if [ -z "$REPO_URL" ]; then + echo "[$(date)] $REPO_PATH: misconfigured public.conf, skipping" >> "$LOGFILE" + else + OUTPUT=$(git push --mirror "$REPO_URL" 2>&1) + if [ $? -ne 0 ]; then + echo "[$(date)] MIRROR FAILED $REPO_PATH -> $REPO_URL" >> "$LOGFILE" + echo "$OUTPUT" >> "$LOGFILE" + fi + fi fi -echo "[$(date)] BEGIN PUSH $REPO_PATH" >> "$LOGFILE" -git push --mirror "$REPO_URL" >> "$LOGFILE" 2>&1 -echo "[$(date)] END PUSH $REPO_PATH" >> "$LOGFILE" +# run repo specific post-recieve hook if it existst +REPO_HOOK="$(git rev-parse --git-dir)/hooks/post-receive" +if [ -x "$REPO_HOOK" ]; then + "$REPO_HOOK" "$@" +fi # vim: filetype=bash diff --git a/git-shell-commands/new-project b/git-shell-commands/new-project new file mode 100755 index 0000000..c9804bf --- /dev/null +++ b/git-shell-commands/new-project @@ -0,0 +1,33 @@ +#!/bin/bash +# this script allows the creation of projects over ssh on git server +# public repos will get a public.conf containing the remote +# private repos will just exist on the server +# +# USAGE: +# ssh git@<host> new-project +# - follow the prompts + +REMOTE_BASE_URL = "git@treybastian.com:repos/" +echo "oh look you are starting a project you won't finish again." +echo "What is your projects name?" +read PROJECT_NAME +if [[ $PROJECT_NAME!=*.git ]]; then + PROJECT_NAME="${PROJECT_NAME}.git" +fi +read -p "Is this public?" -n 1 -r +echo + +git --bare init "${PROJECT_NAME}" + +if [[ $REPLY =~ ^[Yy]$ ]]; then + touch "${PROJECT_NAME}/public.conf" + echo "${REMOTE_BASE_URL}/${PROJECT_NAME}" >> "${PROJECT_NAME}/public.conf" + ssh git@treybastian.com new-repo "repos/${PROJECT_NAME}" +fi + +echo "git url: ${USER}@${HOSTNAME}:${PROJECT_NAME}" +if [[ $REMOTE_URL ]]; then + echo "public repo: ${REMOTE_BASE_URL}/${PROJECT_NAME}" +fi + +#vim: filetype=bash diff --git a/git-shell-commands/new-repo b/git-shell-commands/new-repo index 52bd69f..f6b2dc8 100755 --- a/git-shell-commands/new-repo +++ b/git-shell-commands/new-repo @@ -1,29 +1,19 @@ #!/bin/bash # this script allows the creation of new repos over ssh on git server -# public repos will get a knot.conf containing the remote -# private repos will just exist on the server # USAGE: -# ssh git@<host> new-repo +# ssh git@<host> new-repo <project name> # - follow the prompts -echo "oh look you are starting a project you won't finish again." -echo "What is your projects name?" -read PROJECT_NAME +$PROJECT_NAME = $1 +if [[ -z "$1" ]]; then + echo "project name cannot be empty" + exit 1 +fi if [[ $PROJECT_NAME!=*.git ]]; then PROJECT_NAME="${PROJECT_NAME}.git" fi -echo "What's the mirror repo remote url?(leave blank if private)" -read REMOTE_URL git --bare init "${PROJECT_NAME}" -if [[ $REMOTE_URL ]]; then - touch "${PROJECT_NAME}/knot.conf" - echo "${REMOTE_URL}" >> "${PROJECT_NAME}/knot.conf" -fi - -echo "git url: ${USER}@${HOSTNAME}:${PROJECT_NAME}" -if [[ $REMOTE_URL ]]; then - echo "public repo: ${REMOTE_URL}" -fi +echo "project created" #vim: filetype=bash |
