]> git.armaanb.net Git - bin.git/commitdiff
git-mirror: add many more options
authorArmaan Bhojwani <me@armaanb.net>
Sat, 6 Mar 2021 15:37:42 +0000 (10:37 -0500)
committerArmaan Bhojwani <me@armaanb.net>
Sat, 6 Mar 2021 15:45:10 +0000 (10:45 -0500)
git-mirror

index 5807b87e09c8cf104c50f4a2f110ce23ce3de50f..bdb22f22c2435b011a11127f363fbb3882320567 100755 (executable)
@@ -1,33 +1,63 @@
-#!/usr/bin/sh -e
+#!/usr/bin/sh
+# Mirror some Git repos
 
-case ${1} in
-  -h | --help)
-    echo "Usage: git-mirror [path to repos] [path to log file] [html directory]"
-    echo "relative paths are not supported."
-    exit 1
-    ;;
-esac
+usage() {
+  echo 'Usage: git-mirror [command] [arguments]
+  git-mirror run [path to repos] [path to log file] [html directory]
+  git-mirror gen-url [path to repo] -- generate url file in repo
+  git-mirror help -- show this message
 
-[ -z ${3} ] && echo "not enough arguments" && exit 1
-[ -z $(which stagit) ] && echo "please install stagit" && exit 1
+  relative paths are not supported, but globs are.
+  To use, first clone the wanted somewhere repos with the --mirror flag.'
+}
 
-cd ${1}
+run() {
+  [ -z ${3} ] && echo "not enough arguments" && exit 1
+  [ -z $(which stagit) ] && echo "please install stagit" && exit 1
 
-[ -d ${3} ] || mkdir ${3}
-stagit-index ./* > ${3}/index.html
-cp /usr/share/doc/stagit/style.css ${3}
+  cd ${1}
 
-while :; do
+  [ -d ${3} ] || mkdir ${3}
+  stagit-index ./* > ${3}/index.html
+  cp /usr/share/doc/stagit/style.css ${3}
+
+  while :; do
+    find ${1} -maxdepth 2 -name '*.git' | \
+      while read dir; do
+        newdir=${3}/$(basename ${dir} .git)
+        [ -d ${newdir} ] || mkdir ${newdir}
+        cd ${newdir}
+        stagit ${dir}
+        cp /usr/share/doc/stagit/style.css .
+        git -C ${dir} fetch --tags
+        echo $(date -Iseconds) ' | ' ${dir} | tee -a ${2}
+        echo $(tail -n 1500 ${2}) > ${2}
+      done
+    sleep 600
+  done
+}
+
+gen_url() {
   find ${1} -maxdepth 2 -name '*.git' | \
     while read dir; do
-      newdir=${3}/$(basename ${dir} .git)
-      [ -d ${newdir} ] || mkdir ${newdir}
-      cd ${newdir}
-      stagit ${dir}
-      cp /usr/share/doc/stagit/style.css .
-      git -C ${dir} fetch --tags
-      echo $(date -Iseconds) ' | ' ${dir} | tee -a ${2}
-      echo $(tail -n 1500 ${2}) > ${2}
+      git -C $dir remote get-url origin > $dir/url
     done
-  sleep 600
-done
+}
+
+case ${1} in
+  -h | --help | help)
+    usage
+    ;;
+  run)
+    shift 1
+    run $@
+    ;;
+  gen-url)
+    shift 1
+    gen_url $@
+    ;;
+  *)
+    usage
+    exit 1
+    ;;
+esac