]> git.armaanb.net Git - bin.git/blob - git-mirror
git-mirror: remove css copying
[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} && stagit-index ${1}/*
23
24   while :; do
25     find "$1" -name '*.git' -type d | \
26       while read dir; 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           git -C ${dir} fetch --tags
37           echo $(date -Iseconds) ' | ' ${dir} | tee -a ${2}
38           echo $(tail -n 1500 ${2}) > ${2}
39         done
40         sleep 600
41       done
42     }
43
44   gen_url() {
45     find ${1} -maxdepth 2 -name '*.git' | \
46       while read dir; do
47         $(git -C $dir remote get-url origin) > $dir/url
48       done
49     }
50
51   case ${1} in
52     -h | --help | help)
53       usage
54       ;;
55     run)
56       shift 1
57       run $@
58       ;;
59     gen-url)
60       shift 1
61       gen_url $@
62       ;;
63     *)
64       usage
65       exit 1
66       ;;
67   esac