]> git.armaanb.net Git - bin.git/blob - git-mirror
git-mirror: switch "find | while read" to "for in"
[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
18   cd ${1}
19
20   [ -d ${3} ] || mkdir ${3}
21   stagit-index ./* > ${3}/index.html
22   cp /usr/share/doc/stagit/style.css ${3}
23
24   while :; do
25       for dir in "${1}/*.git"; do
26         newdir=${3}/$(basename ${dir} .git)
27         [ -d ${newdir} ] || mkdir ${newdir}
28         cd ${newdir}
29         stagit ${dir}
30         cp /usr/share/doc/stagit/style.css .
31         git -C ${dir} fetch --tags
32         echo $(date -Iseconds) ' | ' ${dir} | tee -a ${2}
33         echo $(tail -n 1500 ${2}) > ${2}
34       done
35     sleep 600
36   done
37 }
38
39 gen_url() {
40   find ${1} -maxdepth 2 -name '*.git' | \
41     while read dir; do
42       $(git -C $dir remote get-url origin) > $dir/url
43     done
44 }
45
46 case ${1} in
47   -h | --help | help)
48     usage
49     ;;
50   run)
51     shift 1
52     run $@
53     ;;
54   gen-url)
55     shift 1
56     gen_url $@
57     ;;
58   *)
59     usage
60     exit 1
61     ;;
62 esac