git.jamzattack.xyz

Scripts for working with stagit
git clone https://git.jamzattack.xyz/git.jamzattack.xyz
Log | Files | Refs

create.sh (2533B)


      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.png and favicon.png manually, a style.css example
      7 #   is included.
      8 #
      9 # - write clone url, for example "git://git.codemadness.org/dir" to the "url"
     10 #   file for each repo.
     11 # - write owner of repo to the "owner" file.
     12 # - write description in "description" file.
     13 #
     14 # Usage:
     15 # - mkdir -p htmldir && cd htmldir
     16 # - sh example_create.sh
     17 
     18 cd /var/www/git
     19 
     20 # path must be absolute.
     21 reposdir="/home/git"
     22 curdir="$(pwd)"
     23 
     24 if [ $# -ge 1 ]; then
     25     wanted="${reposdir}/${@}.git"
     26 else
     27     wanted="${reposdir}/*.git/"
     28 fi
     29 
     30 stagit-index "${reposdir}/"*.git/ | sed 's/log\.html//g' > "${curdir}/index.html"
     31 
     32 org2html() {
     33     [ -f "${curdir}/htmlize.el" ] ||
     34 	wget -O "${curdir}/htmlize.el" \
     35 	     'https://raw.githubusercontent.com/hniksic/emacs-htmlize/master/htmlize.el'
     36     emacs -Q --batch --debug -l /var/www/git/gen.el --eval \
     37 	  "(generate-html-file \"$1\" \"$2\")"
     38 }
     39 
     40 md2html() {
     41     pandoc -i "${1}" -o "${2}"
     42 }
     43 
     44 # make files per repo.
     45 for dir in $wanted; do
     46     # strip .git suffix.
     47     r=$(basename "${dir}")
     48     d=$(basename "${dir}" ".git")
     49     printf "%s... " "${d}"
     50 
     51     rm -f "${curdir}/${d}/index.html"
     52     mkdir -p "${curdir}/${d}"
     53     cd "${curdir}/${d}" || exit 2
     54 
     55     stagit -c ".cache" "${reposdir}/${r}"
     56 
     57     cd "${reposdir}/${r}" || exit 2
     58     # now in /home/git/<repo>
     59 
     60     ### Create html README
     61     mkdir -p "/tmp/${d}"
     62     if [ -n "$(git ls-tree HEAD config.org)" ]; then
     63 	# config.org
     64 	git show HEAD:config.org > "/tmp/${d}/config.org"
     65 	org2html "/tmp/${d}/config.org" "/tmp/${d}/out.html"
     66     elif [ -n "$(git ls-tree HEAD README.org)" ]; then
     67 	# README.org
     68 	git show HEAD:README.org > "/tmp/${d}/README.org"
     69 	org2html "/tmp/${d}/README.org" "/tmp/${d}/out.html"
     70     elif [ -n "$(git ls-tree HEAD README.md)" ]; then
     71 	# README.md
     72 	git show HEAD:README.md > "/tmp/${d}/README.md"
     73 	md2html "/tmp/${d}/README.md" "/tmp/${d}/out.html"
     74     fi
     75 
     76     cd "${curdir}/${d}" || exit 2
     77     # Now in /var/www/git/<repo>
     78     if [ -f "/tmp/${d}/out.html" ]; then
     79 	cat "${curdir}/${d}/files.html" "/tmp/${d}/out.html" > "${curdir}/${d}/index.html"
     80     else
     81 	ln -sf files.html index.html 
     82     fi
     83 
     84    # symlinks
     85     ln -sf ../style.css style.css
     86     ln -sf ../logo.png logo.png
     87     ln -sf ../favicon.png favicon.png
     88 
     89     echo "done"
     90 done
     91 
     92 # (copy-file (buffer-file-name) "/ssh:git@jamzattack.xyz:/var/www/git/create.sh" t)