commit 54773b9f900461476809526459fc63201ce40c01
parent 41cece624763d5b9501e662f0a633afeb3dfa29f
Author: deurzen <max@deurzen.net>
Date: Wed, 25 May 2022 04:28:37 +0200
adds generation and automation scripts
Diffstat:
5 files changed, 124 insertions(+), 116 deletions(-)
diff --git a/example_create.sh b/example_create.sh
@@ -1,43 +0,0 @@
-#!/bin/sh
-# - Makes index for repositories in a single directory.
-# - Makes static pages for each repository directory.
-#
-# NOTE, things to do manually (once) before running this script:
-# - copy style.css, logo.png and favicon.png manually, a style.css example
-# is included.
-#
-# - write clone URL, for example "git://git.codemadness.org/dir" to the "url"
-# file for each repo.
-# - write owner of repo to the "owner" file.
-# - write description in "description" file.
-#
-# Usage:
-# - mkdir -p htmldir && cd htmldir
-# - sh example_create.sh
-
-# path must be absolute.
-reposdir="/var/www/domains/git.codemadness.nl/home/src"
-curdir="$(pwd)"
-
-# make index.
-stagit-index "${reposdir}/"*/ > "${curdir}/index.html"
-
-# make files per repo.
-for dir in "${reposdir}/"*/; do
- # strip .git suffix.
- r=$(basename "${dir}")
- d=$(basename "${dir}" ".git")
- printf "%s... " "${d}"
-
- mkdir -p "${curdir}/${d}"
- cd "${curdir}/${d}" || continue
- stagit -c ".cache" -u "https://git.codemadness.nl/$d/" "${reposdir}/${r}"
-
- # symlinks
- ln -sf log.html index.html
- ln -sf ../style.css style.css
- ln -sf ../logo.png logo.png
- ln -sf ../favicon.png favicon.png
-
- echo "done"
-done
diff --git a/example_post-receive.sh b/example_post-receive.sh
@@ -1,73 +0,0 @@
-#!/bin/sh
-# generic git post-receive hook.
-# change the config options below and call this script in your post-receive
-# hook or symlink it.
-#
-# usage: $0 [name]
-#
-# if name is not set the basename of the current directory is used,
-# this is the directory of the repo when called from the post-receive script.
-
-# NOTE: needs to be set for correct locale (expects UTF-8) otherwise the
-# default is LC_CTYPE="POSIX".
-export LC_CTYPE="en_US.UTF-8"
-
-name="$1"
-if test "${name}" = ""; then
- name=$(basename "$(pwd)")
-fi
-
-# config
-# paths must be absolute.
-reposdir="/home/src/src"
-dir="${reposdir}/${name}"
-htmldir="/home/www/domains/git.codemadness.org/htdocs"
-stagitdir="/"
-destdir="${htmldir}${stagitdir}"
-cachefile=".htmlcache"
-# /config
-
-if ! test -d "${dir}"; then
- echo "${dir} does not exist" >&2
- exit 1
-fi
-cd "${dir}" || exit 1
-
-# detect git push -f
-force=0
-while read -r old new ref; do
- test "${old}" = "0000000000000000000000000000000000000000" && continue
- test "${new}" = "0000000000000000000000000000000000000000" && continue
-
- hasrevs=$(git rev-list "${old}" "^${new}" | sed 1q)
- if test -n "${hasrevs}"; then
- force=1
- break
- fi
-done
-
-# strip .git suffix.
-r=$(basename "${name}")
-d=$(basename "${name}" ".git")
-printf "[%s] stagit HTML pages... " "${d}"
-
-mkdir -p "${destdir}/${d}"
-cd "${destdir}/${d}" || exit 1
-
-# remove commits and ${cachefile} on git push -f, this recreated later on.
-if test "${force}" = "1"; then
- rm -f "${cachefile}"
- rm -rf "commit"
-fi
-
-# make index.
-stagit-index "${reposdir}/"*/ > "${destdir}/index.html"
-
-# make pages.
-stagit -c "${cachefile}" -u "https://git.codemadness.nl/$d/" "${reposdir}/${r}"
-
-ln -sf log.html index.html
-ln -sf ../style.css style.css
-ln -sf ../logo.png logo.png
-
-echo "done"
diff --git a/generate.sh b/generate.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+GITDIR="/srv/git"
+WEBDIR="/var/www/html"
+
+stagit-index "${GITDIR}/"*/ > "${WEBDIR}/index.html"
+
+# make files per repo
+for repo in "${GITDIR}/"*/; do
+ # strip .git suffix
+ REPO_DIR=$(basename "${repo}")
+ REPO_NAME=$(basename "${repo}" ".git")
+ printf "%s... " "${REPO_NAME}"
+
+ mkdir -p "${WEBDIR}/${REPO_NAME}"
+ cd "${WEBDIR}/${REPO_NAME}" || continue
+ stagit -c ".cache" "${GITDIR}/${REPO_DIR}"
+
+ ln -sf log.html index.html
+ ln -sf ../style.css style.css
+ ln -sf ../logo.png logo.png
+ ln -sf ../favicon.png favicon.png
+
+ echo "done"
+done
diff --git a/new-repo b/new-repo
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+set -Eeo pipefail
+
+DOMAIN="git.mydomain.net"
+OWNER="<owner name>"
+
+if ! [ $# -eq 3 ]; then
+ >&2 echo "invalid number of arguments"
+ echo "new-repo: add a new git repo"
+ echo "usage: new-repo <private|public> <name> <description>"
+ exit 1
+fi
+
+if [[ "$1" == "private" ]]; then
+ PRIVATE=1
+ unset PUBLIC
+elif [[ "$1" == "public" ]]; then
+ PUBLIC=1
+else
+ >&2 echo "invalid first argument: $1"
+ echo "new-repo: add a new git repo"
+ echo "usage: new-repo <private|public> <name> <description>"
+ exit 1
+fi
+shift
+
+NAME="$1"
+shift
+
+DESCRIPTION="$@"
+
+while (( "$#" )); do
+ case "$1" in
+ -h|--help)
+ echo "new-repo: add a new git repo"
+ echo "usage: new-repo <private|public> <name> <description>"
+ exit
+ ;;
+ -*|--*=)
+ >&2 echo "new-repo: invalid option $1"
+ exit 1
+ ;;
+ *)
+ shift
+ ;;
+ esac
+done
+
+sudo su git -s /bin/bash <<EOF
+mkdir /srv/git/${NAME}.git && cd /srv/git/${NAME}.git && git init --bare
+test $PUBLIC && touch /srv/git/${NAME}.git/git-daemon-export-ok
+echo "$DESCRIPTION" >| /srv/git/${NAME}.git/description
+echo "$OWNER" >| /srv/git/${NAME}.git/owner
+echo "git://${DOMAIN}/${NAME}.git" >| /srv/git/${NAME}.git/url
+cp ~/post-receive /srv/git/${NAME}.git/hooks/post-receive
+echo ""
+echo "generating static pages"
+cd /var/www/html && ./generate.sh
+echo ""
+echo "push to: ${DOMAIN}:/srv/git/${NAME}.git"
+echo "config:"
+echo '[remote "self"]'
+echo " url = self1:/srv/git/${NAME}.git"
+echo ' fetch = +refs/heads/*:refs/remotes/self/*'
+echo ""
+echo "pull from: git@${DOMAIN}/${NAME}.git"
+EOF
diff --git a/post-receive b/post-receive
@@ -0,0 +1,32 @@
+#!/usr/bin/env bash
+
+if [ $(git rev-parse --is-bare-repository) = true ]; then
+ REPOSITORY_BASENAME=$(basename "$PWD")
+else
+ REPOSITORY_BASENAME=$(basename $(readlink -nf "$PWD"/..))
+fi
+
+REPOSITORY_NAME=${REPOSITORY_BASENAME%.git}
+
+GITDIR="/srv/git"
+WEBDIR="/var/www/html"
+
+FORCE=0
+while read -r old new ref; do
+ HASREVS=$(git rev-list "$old" "^$new" | sed 1q)
+ if test -n "$HASREVS"; then
+ FORCE=1
+ break
+ fi
+done
+
+if test "$FORCE" = "1"; then
+ rm -rf "${WEBDIR}/${REPOSITORY_NAME}"
+fi
+
+cd /var/www/html || exit 1
+
+echo ''
+echo 'generating static pages'
+./generate.sh
+echo ''