]> git.armaanb.net Git - bin.git/blob - git-mirror
git-mirror: minify HTML
[bin.git] / git-mirror
1 #!/usr/bin/sh
2 # Mirror some Git repos
3
4 usage() {
5   echo 'Usage: git-mirror [command] [arguments]
6   git-mirror run [path to repos] [path to log file] [html directory]
7   git-mirror gen-url [path to repo] -- generate url file in repo
8   git-mirror help -- show this message
9
10   relative paths are not supported, but globs are.
11   To use, first clone the wanted somewhere repos with the --mirror flag.'
12 }
13
14 run() {
15   [ -z ${3} ] && echo "not enough arguments" && exit 1
16   [ -z $(which stagit) ] && echo "please install stagit" && exit 1
17   [ -z $(which minify) ] && echo "please install minify" && exit 1
18
19   cd ${1}
20
21   [ -d ${3} ] || mkdir ${3}
22   cd ${3} && stagit-index
23   cp /usr/share/doc/stagit/style.css ${3}
24
25   while :; do
26       for dir in "${1}/*.git"; do
27         newdir=${3}/$(basename ${dir} .git)
28         [ -d ${newdir} ] || mkdir ${newdir}
29         cd ${newdir}
30         stagit ${dir}
31         find . -type f \( -name '*.html' -or -name '*.xml' \) | \
32           while read i ; do
33             minify ${i} > ${i}.tmp
34             mv ${i}.tmp ${i}
35           done
36         cp /usr/share/doc/stagit/style.css .
37         git -C ${dir} fetch --tags
38         echo $(date -Iseconds) ' | ' ${dir} | tee -a ${2}
39         echo $(tail -n 1500 ${2}) > ${2}
40       done
41     sleep 600
42   done
43 }
44
45 gen_url() {
46   find ${1} -maxdepth 2 -name '*.git' | \
47     while read dir; do
48       $(git -C $dir remote get-url origin) > $dir/url
49     done
50 }
51
52 case ${1} in
53   -h | --help | help)
54     usage
55     ;;
56   run)
57     shift 1
58     run $@
59     ;;
60   gen-url)
61     shift 1
62     gen_url $@
63     ;;
64   *)
65     usage
66     exit 1
67     ;;
68 esac