gitpages

A collection of scripts to securely webhost and publish git repositories.
git clone https://scm.kuandu.systems/git-raw/gitpages.git
Log | Files | Refs | README | LICENSE

gitpages-regenerate.sh (2227B)


      1 #!/bin/sh
      2 #
      3 # Copyright (c) 2026 Fred Großkopf
      4 #
      5 # Permission to use, copy, modify, and/or distribute this software for any
      6 # purpose with or without fee is hereby granted, provided that the above
      7 # copyright notice and this permission notice appear in all copies.
      8 #
      9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     16 
     17 set -eu
     18 
     19 # Ensure a stable environment
     20 PATH=/usr/local/bin:/usr/bin:/bin:$PATH
     21 
     22 error() {
     23   printf 'error: %s\n' "$1" >&2
     24   exit 1
     25 }
     26 
     27 # Consistent awk-based config retrieval
     28 get_config_val() {
     29   awk -F '=' -v key="$1" '$1 == key {gsub(/[[:space:]]/, "", $2); print $2}' "$2" | tail -n 1
     30 }
     31 
     32 main() {
     33   CONFIG_PATH="/etc/gitpages.conf"
     34 
     35   # Optional -c argument parsing
     36   if [ "${1:-}" = "-c" ]; then
     37     [ $# -lt 2 ] && { printf "usage: $(basename "$0") [-c config]\n"; exit 1; }
     38     CONFIG_PATH="$2"
     39     shift 2
     40   fi
     41 
     42   [ -f "$CONFIG_PATH" ] || error "Config file $CONFIG_PATH not found"
     43 
     44   # Retrieve values
     45   GIT_SRC=$(get_config_val "GIT_SRC" "$CONFIG_PATH")
     46   GIT_RAW=$(get_config_val "GIT_RAW" "$CONFIG_PATH")
     47   
     48   [ -z "$GIT_SRC" ] || [ -z "$GIT_RAW" ] && error "GIT_SRC or GIT_RAW missing in config"
     49   [ -d "$GIT_SRC" ] || error "GIT_SRC directory $GIT_SRC does not exist"
     50   [ -d "$GIT_RAW" ] || error "GIT_RAW directory $GIT_RAW does not exist"
     51 
     52   printf 'info: 1/2 Mirroring repos %s → %s\n' "$GIT_SRC" "$GIT_RAW"
     53   gitpages-mirror-git.sh "$GIT_SRC" "$GIT_RAW" || error "Mirroring failed"
     54 
     55   printf 'info: 2/2 Generating HTML for all repos in %s\n' "$GIT_RAW"
     56   
     57   # Iterate over each .git directory and call gitpages.sh
     58   for repo in "$GIT_RAW"/*.git; do
     59     [ -e "$repo" ] || continue
     60     printf '  Processing: %s\n' "$(basename "$repo")"
     61     gitpages.sh -c "$CONFIG_PATH" "$repo" || error "HTML generation failed for $repo"
     62   done
     63 }
     64 
     65 main "$@"