resume_page

Log | Files | Refs | README

sync.sh (2072B)


      1 #!/bin/sh
      2 set -eu
      3 export GIT_TERMINAL_PROMPT=0
      4 mkdir -p /git /www
      5 rm -rf /git/.clone
      6 
      7 while :; do
      8     echo 'Synchronizing repositories'
      9     tr -d '\r' < /config/repos.txt > /tmp/repos.txt
     10     while IFS= read -r url || [ -n "$url" ]; do
     11         case "$url" in ''|'#'*) continue ;; esac
     12         name=${url##*/}
     13         name=${name%.git}
     14         case "$name" in ''|.*|*[!a-zA-Z0-9._-]*) echo "Invalid name: $name"; continue ;; esac
     15         mirror="/git/$name.git"
     16         if [ -d "$mirror" ]; then
     17             if git --git-dir="$mirror" fetch --atomic --prune origin; then
     18                 echo "Updated $name"
     19             else
     20                 echo "Unavailable: $name; keeping local mirror"
     21             fi
     22         elif git clone --mirror "$url" /git/.clone; then
     23             mv /git/.clone "$mirror"
     24             : > "$mirror/description"
     25             echo "Cloned $name"
     26         else
     27             rm -rf /git/.clone
     28             echo "Could not clone $name; skipping"
     29         fi
     30     done < /tmp/repos.txt
     31 
     32     echo 'Generating stagit pages'
     33     # Build in the inactive directory, then switch Caddy to the finished site.
     34     build=/www/a
     35     [ "$(readlink /www/current || true)" != a ] || build=/www/b
     36     rm -rf "$build"
     37     mkdir "$build"
     38     cp /assets/* "$build/"
     39     for mirror in /git/*.git; do
     40         [ -d "$mirror" ] || continue
     41         name=${mirror##*/}
     42         mkdir "$build/${name%.git}"
     43         (cd "$build/${name%.git}" && stagit "$mirror" &&
     44             ln -s log.html index.html &&
     45             ln -s ../style.css ../favicon.png ../logo.png .)
     46     done
     47     set -- /git/*.git
     48     if [ -d "$1" ]; then
     49         stagit-index "$@" > "$build/index.html"
     50     else
     51         echo '<!doctype html><title>Repositories</title><link rel="stylesheet" href="style.css"><link rel="icon" href="favicon.png"><img src="logo.png" alt=""><p>No repositories configured.</p>' > "$build/index.html"
     52     fi
     53     ln -sfn "${build##*/}" /www/current.new
     54     mv -Tf /www/current.new /www/current
     55     echo 'Site published; next synchronization in 24 hours'
     56     sleep 86400 &
     57     wait "$!"
     58 done