git_infra

Git infra scripts for git.bracken.jp
git clone https://git.bracken.jp/git_infra.git
Log | Files | Refs | LICENSE

gitout (2551B)


      1 #!/bin/sh -e
      2 
      3 export LC_CTYPE="en_US.UTF-8"
      4 
      5 # Add Mastodon verification URL to index header.
      6 me_url="https://bsd.network/@cbracken"
      7 
      8 # HTML root directory into which gitout will write.
      9 www_root="/usr/local/www/git.bracken.jp"
     10 
     11 # Hooks are called from the repo directory.
     12 repo_dir=$(pwd)
     13 
     14 # The gitout cache file.
     15 # This is an optimisation to avoid regenerating all pages on each push.
     16 cachefile="${repo_dir}/.htmlcache"
     17 
     18 # The directory under which all repos are located.
     19 # Repos under this directory will be added to the repo index page.
     20 repos_root=$(dirname "$repo_dir")
     21 
     22 # The user-friendly name of the repository.
     23 repo_name=$(basename "$repo_dir" '.git')
     24 
     25 # Detect --force pushes.
     26 cd "${repo_dir}" || exit 1
     27 force=0
     28 while read -r old new _; do
     29   [ "${old}" = "0000000000000000000000000000000000000000" ] && continue
     30   [ "${new}" = "0000000000000000000000000000000000000000" ] && continue
     31 
     32   hasrevs=$(git rev-list "$old" "^$new" | sed 1q)
     33   if [ -n "$hasrevs" ]; then
     34     echo "[gitout] Force push detected: cleaning cache"
     35     force=1
     36     break
     37   fi
     38 done
     39 
     40 # If there was a --force push, delete all existing pages. The lack of a cache
     41 # file will trigger a full rebuild below.
     42 if [ "$force" = "1" ]; then
     43   rm -f "$cachefile"
     44   rm -rf "commit" "file"
     45 fi
     46 
     47 # Build the pages. If $cachefile is not present, a full rebuild is performed.
     48 if [ -e "${repo_dir}/git-daemon-export-ok" ]; then
     49   # Change to the directory where we will output HTML pages.
     50   repo_web_dir="${www_root}/${repo_name}"
     51   mkdir -p "$repo_web_dir"
     52   cd "$repo_web_dir" || exit 1
     53 
     54   # Generate the index page.
     55   # Any repo containing a gitout-no-index file will not be indexed.
     56   echo "[gitout] Building repo index"
     57   find "${repos_root}/." -maxdepth 1            \
     58     -type d                                     \
     59     -name "*.git"                               \
     60     -exec test -e "{}/git-daemon-export-ok" \;  \
     61     -exec test ! -e "{}/gitout-no-index" \;     \
     62     -print                                      \
     63     | sort -f                                   \
     64     | sed -e 's/"/"\\""/g' -e 's/.*/"&"/'       \
     65     | xargs gitout_index -m "$me_url"           \
     66     > "${www_root}/index.html"
     67 
     68   # Rebuild the pages for the repo (including for unlisted repos).
     69   echo "[gitout] Building pages"
     70   gitout -c "$cachefile" "$repo_dir"
     71 
     72   # use log as index page
     73   echo "[gitout] Linking assets"
     74   ln -sf log.html index.html
     75   ln -sf ../style.css style.css
     76   ln -sf ../logo.png logo.png
     77   ln -sf ../favicon.png favicon.png
     78 else
     79   echo "[gitout] Not building pages: private repo"
     80 fi