example_create.sh (2400B) - 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 to $assetdir. 7 # - modify the at the start of the script with your own. 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 # - write category in "category" file, if there is no category, the repository 15 # will be unlisted on stagit. 16 # 17 # Usage: 18 # - sh example_create.sh 19 20 # paths must be absolute 21 reposdir="/srv/git" 22 webdir="/srv/git/html" 23 cachefile=".stagit-build-cache" 24 assetdir="/usr/local/share/doc/stagit" 25 26 is_public_and_listed() { 27 if [ ! -f "$1/git-daemon-export-ok" ] || [ ! -f "$1/category" ]; then 28 return 1 29 fi 30 return 0 31 } 32 33 make_repo_web() { 34 reponame="$(basename "$1" ".git")" 35 printf "[%s] stagit HTML pages... " "$reponame" 36 37 mkdir -p "$webdir/$reponame" 38 cd "$webdir/$reponame" || return 1 39 40 # make pages 41 stagit -c "$cachefile" -u "https://git.oscarbenedito.com/$reponame/" "$1" 42 43 # symlinks 44 [ -f "about.html" ] \ 45 && ln -sf "about.html" "index.html" \ 46 || ln -sf "log.html" "index.html" 47 48 echo "done" 49 } 50 51 make_stagit_index() { 52 printf "Generating stagit index... " 53 54 # generate index arguments 55 args="" 56 for category in "Projects" "Personal setup" "Miscellanea"; do 57 args="$args -c \"$category\"" 58 for repo in "$reposdir/"*.git/; do 59 repo="${repo%/}" 60 is_public_and_listed "$repo" || continue 61 [ "$(cat "$repo/category")" = "$category" ] && args="$args $repo" 62 done 63 done 64 65 # make index 66 echo "$args" | xargs stagit-index > "$webdir/index.html" 67 68 echo "done" 69 } 70 71 # clean webdir 72 rm -rf "$webdir" 73 mkdir -p "$webdir" || exit 1 74 75 # set assets if not already there 76 ln -s "$assetdir/style.css" "$webdir/style.css" 2> /dev/null 77 ln -s "$assetdir/logo.svg" "$webdir/logo.svg" 2> /dev/null 78 ln -s "$assetdir/favicon.ico" "$webdir/favicon.ico" 2> /dev/null 79 80 # make files per repo 81 for repo in "$reposdir/"*.git/; do 82 repo="${repo%/}" 83 is_public_and_listed "$repo" || continue 84 85 make_repo_web "$repo" 86 done 87 88 make_stagit_index