]> git.armaanb.net Git - bin.git/blob - git-mirror
git-mirror: regenerate index on every run
[bin.git] / git-mirror
1 #!/usr/bin/env 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}
23
24   while :; do
25     stagit-index ${1}/*
26     find "$1" -name '*.git' -type d | \
27       while read dir; do
28         newdir=${3}/$(basename ${dir} .git)
29         [ -d ${newdir} ] || mkdir ${newdir}
30         cd ${newdir}
31         stagit ${dir}
32         cp "$1/logo.png" .
33         ln -s logo.png favicon.png
34         find . -type f \( -name '*.html' -or -name '*.xml' \) | \
35           while read i ; do
36             minify ${i} > ${i}.tmp
37             mv ${i}.tmp ${i}
38           done
39           git -C ${dir} fetch --tags
40           echo $(date -Iseconds) ' | ' ${dir} | tee -a ${2}
41           echo $(tail -n 1500 ${2}) > ${2}
42         done
43         sleep 600
44       done
45     }
46
47   gen_url() {
48     find ${1} -maxdepth 2 -name '*.git' | \
49       while read dir; do
50         $(git -C $dir remote get-url origin) > $dir/url
51       done
52     }
53
54   case ${1} in
55     -h | --help | help)
56       usage
57       ;;
58     run)
59       shift 1
60       run $@
61       ;;
62     gen-url)
63       shift 1
64       gen_url $@
65       ;;
66     *)
67       usage
68       exit 1
69       ;;
70   esac