example_create.sh (2349B) - raw


      1 #!/bin/sh
      2 # - Makes index for repositories in a single directory.
      3 # - Makes static pages for each repository directory.
      4 #
      5 # NOTE, things to do manually (once) before running this script:
      6 # - copy style.css, logo.svg and favicon.ico manually, a style.css example
      7 #   is included.
      8 # - modify the categories in the for loop with your own.
      9 #
     10 # - write clone url, for example "git://git.codemadness.org/dir" to the "url"
     11 #   file for each repo.
     12 # - write owner of repo to the "owner" file.
     13 # - write description in "description" file.
     14 #
     15 # Usage:
     16 # - mkdir -p htmldir && cd htmldir
     17 # - sh example_create.sh
     18 
     19 # path must be absolute
     20 reposdir="/srv/git"
     21 webdir="/srv/git/html"
     22 defaultdir="/usr/local/share/doc/stagit"
     23 
     24 mkdir -p "$webdir" || exit 1
     25 
     26 # set assets if not already there
     27 ln -s "$defaultdir/style.css" "$webdir/style.css" 2> /dev/null
     28 ln -s "$defaultdir/logo.svg" "$webdir/logo.svg" 2> /dev/null
     29 ln -s "$defaultdir/favicon.ico" "$webdir/favicon.ico" 2> /dev/null
     30 
     31 # clean
     32 for dir in "$webdir/"*/; do
     33     rm -rf "$dir"
     34 done
     35 
     36 # make files per repo
     37 for dir in "$reposdir/"*.git/; do
     38     dir="${dir%/}"
     39     [ ! -f "$dir/git-daemon-export-ok" ] && continue
     40     [ ! -f "$dir/category" ] && [ -z "$stagit_uncat" ] && stagit_uncat="1"
     41 
     42     # strip .git suffix
     43     r="$(basename "$dir")"
     44     d="$(basename "$dir" ".git")"
     45     printf "%s... " "$d"
     46 
     47     mkdir -p "$webdir/$d"
     48     cd "$webdir/$d" || continue
     49     stagit -c ".stagit-build-cache" -u "https://git.oscarbenedito.com/$d/" "$reposdir/$r"
     50 
     51     # symlinks
     52     [ -f "about.html" ] \
     53         && ln -sf "about.html" "index.html" \
     54         || ln -sf "log.html" "index.html"
     55     ln -sfT "$reposdir/$r" ".git"
     56 
     57     echo "done"
     58 done
     59 
     60 # generate index arguments
     61 args=""
     62 for cat in "Projects" "Personal setup" "Miscellanea"; do
     63     args="$args -c \"$cat\""
     64     for dir in "$reposdir/"*.git/; do
     65         dir="${dir%/}"
     66         [ -f "$dir/git-daemon-export-ok" ] && [ -f "$dir/category" ] && \
     67             [ "$(cat "$dir/category")" = "$cat" ] && \
     68             args="$args $dir"
     69     done
     70 done
     71 
     72 if [ -n "$stagit_uncat" ]; then
     73     args="$args -c Uncategorized"
     74     for dir in "$reposdir/"*.git/; do
     75         dir="${dir%/}"
     76         [ -f "$dir/git-daemon-export-ok" ] && [ ! -f "$dir/category" ] && \
     77             args="$args $dir"
     78     done
     79 fi
     80 
     81 # make index
     82 echo "$args" | xargs stagit-index > "$webdir/index.html"