git-scripts

Scripts for managing (sta-)git repos
git clone git://git.christianermann.dev/{name}
Log | Files | Refs | LICENSE

commit cf68d94a0c7bcb5e18f45ba8cc3aca4b41296418
parent 8e6e5d8b65a7d7b6d3b9b9626f9530e153e5964d
Author: Christian Ermann <christianermann@gmail.com>
Date:   Wed, 23 Oct 2024 20:22:18 +0000

Split repo index and site generation into separate scripts

Diffstat:
Minstall.sh | 2++
Arepo-full-site.sh | 14++++++++++++++
Arepo-index.sh | 23+++++++++++++++++++++++
Mrepo-site.sh | 50++++++++++++++++++++++----------------------------
4 files changed, 61 insertions(+), 28 deletions(-)

diff --git a/install.sh b/install.sh @@ -1,7 +1,9 @@ #! /bin/sh cp repo-init.sh /usr/local/bin/repo-init +cp repo-index.sh /usr/local/bin/repo-index cp repo-site.sh /usr/local/bin/repo-site +cp repo-full-site.sh /usr/local/bin/repo-full-site cp config.rc /home/git/config.rc chown root:wheel /home/git/config.rc diff --git a/repo-full-site.sh b/repo-full-site.sh @@ -0,0 +1,14 @@ +#! /bin/sh + +set -eu + +CONFIG_PATH="/home/git/config.rc" +. "${CONFIG_PATH}" + +repo-index +for repo in "${GIT_ROOT}"/*; do + if [ -d "${repo}" ]; then + cd "${repo}" || exit 1 + repo-site + fi +done diff --git a/repo-index.sh b/repo-index.sh @@ -0,0 +1,23 @@ +#! /bin/sh + +set -eu + +CONFIG_PATH="/home/git/config.rc" +. "${CONFIG_PATH}" + +# Build a list of all public repos. This is denoted by the existence of a +# file named `git-daemon-export-ok`. +repos="" +repos_stripped="" +for repo in "${GIT_ROOT}"/*; do + if [ -f "${repo}/git-daemon-export-ok" ]; then + repo_stripped="${repo#"$GIT_ROOT/"}" + repos="$repo $repos" + repos_stripped="${repo_stripped} $repos_stripped" + fi +done + +# Build 'repos' page. +cd "${WWW_ROOT}" || exit 1 +stagit-index $repos > index.html +cp "${CSS_PATH}" style.css diff --git a/repo-site.sh b/repo-site.sh @@ -1,36 +1,30 @@ #! /bin/sh +set -euf +export LC_CTYPE="en_US.UTF-8" + CONFIG_PATH="/home/git/config.rc" . "${CONFIG_PATH}" -# Build a list of all public repos. This is denoted by the existence of a -# file named `git-daemon-export-ok`. -repos="" -repos_stripped="" -printf "Publishing:\n" -for repo in "${GIT_ROOT}"/*; do - if [ -f "${repo}/git-daemon-export-ok" ]; then - repo_stripped="${repo#"$GIT_ROOT/"}" - repos="$repo $repos" - repos_stripped="${repo_stripped} $repos_stripped" - printf " - %s\n" "${repo_stripped}" +repo="$(pwd)" +name="$(basename "$repo")" +dest="${WWW_ROOT}/${name}" + +# Check if repo is public. This is denoted by the existence of a file +# named `git-daemon-export-ok`. +if [ ! -f "${repo}/git-daemon-export-ok" ]; then + exit 0 +fi - # Add files to specify repo metadata - printf "%s/%s\n" "${URI_BASE}" "${repo_stripped}" > "${repo}/url" - fi -done +printf "Publishing: %s\n" "${name}" -# Build 'repos' page. -cd "${WWW_ROOT}" -stagit-index $repos > index.html -cp "${CSS_PATH}" style.css +# Add files to specify repo metadata. +printf "%s/%s\n" "${URI_BASE}" "${name}" > "${repo}/url" -# Build pages for each repo. -for repo in $repos_stripped; do - mkdir -p "${WWW_ROOT}/${repo}" && cd "${WWW_ROOT}/${repo}" - stagit "${GIT_ROOT}/${repo}" - ln -sf log.html index.html - ln -sf ../style.css style.css - ln -sf ../logo.png logo.png - ln -sf ../favicon.png favicon.png -done +# Build pages for repo. +mkdir -p "${dest}" && cd "${dest}" || exit 1 +stagit "${repo}" +ln -sf log.html index.html +ln -sf ../style.css style.css +ln -sf ../logo.png logo.png +ln -sf ../favicon.png favicon.png