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