]> git.armaanb.net Git - bin.git/blob - git-mirror
git-mirror: update for loop style
[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   cp /usr/share/doc/stagit/style.css ${3}
24
25   while :; do
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         find . -type f \( -name '*.html' -or -name '*.xml' \) | \
33           while read i ; do
34             minify ${i} > ${i}.tmp
35             mv ${i}.tmp ${i}
36           done
37           cp /usr/share/doc/stagit/style.css .
38           git -C ${dir} fetch --tags
39           echo $(date -Iseconds) ' | ' ${dir} | tee -a ${2}
40           echo $(tail -n 1500 ${2}) > ${2}
41         done
42         sleep 600
43       done
44     }
45
46   gen_url() {
47     find ${1} -maxdepth 2 -name '*.git' | \
48       while read dir; do
49         $(git -C $dir remote get-url origin) > $dir/url
50       done
51     }
52
53   case ${1} in
54     -h | --help | help)
55       usage
56       ;;
57     run)
58       shift 1
59       run $@
60       ;;
61     gen-url)
62       shift 1
63       gen_url $@
64       ;;
65     *)
66       usage
67       exit 1
68       ;;
69   esac