diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 21 | ||||
-rw-r--r-- | mirror.1 | 20 | ||||
-rw-r--r-- | mirror.sh | 24 |
4 files changed, 67 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9eddb41 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +mirror +*.list diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..295812f --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +PREFIX?=/usr/local +BINDIR?=$(PREFIX)/bin +DATADIR?=$(PREFIX)/share +MANDIR?=$(DATADIR)/man/man1 + +all: mirror + +clean: + rm -f mirror + +install: + mkdir -p $(DESTDIR)$(BINDIR) + mkdir -p $(DESTDIR)$(MANDIR) + cp -f mirror $(DESTDIR)$(BINDIR)/mirror + cp -f mirror.1 $(DESTDIR)$(MANDIR)/mirror.1 + +uninstall: + rm -f $(DESTDIR)$(BINDIR)/mirror + rm -f $(DESTDIR)$(MANDIR)/mirror.1 + +.PHONY: all clean install uninstall diff --git a/mirror.1 b/mirror.1 new file mode 100644 index 0000000..3fdeea1 --- /dev/null +++ b/mirror.1 @@ -0,0 +1,20 @@ +.TH mirror 1 "2023-04-15" +.SH NAME +mirror \- copies remote git repositories in bulk +.SH SYNOPSIS +.SY mirror +.RI [ list ] +.YS +.SH DESCRIPTION +This script will read +.I list +file for paths to git repositories, clone them in bare mirror mode or update existing mirrors as necessary. If not +provided +.I list +will default to +.B repositories.list +in the current working directory. +.SH EXIT STATUS +Script is not expected to provide a useful exit status as of now. +.SH SEE ALSO +.BR git (1) diff --git a/mirror.sh b/mirror.sh new file mode 100644 index 0000000..4ded042 --- /dev/null +++ b/mirror.sh @@ -0,0 +1,24 @@ +#!/bin/sh +_path() { + local path="$(url %h%p $1)" + case "${path}" in + *.git) echo "${path}";; + *) echo "${path}.git";; + esac +} + + +_update() { + local repo="$1" + local path="$(_path ${repo})" + test -d "${path}" || git clone -q --mirror "${repo}" "${path}" + git -C "${path}" fetch -q && echo "Updated ${path}" || echo "Failed to update ${path}" +} + + +list="${1:-repositories.list}" +test -f "${list}" || exit 1 +while read repo; do + _update "${repo}" & +done <"${list}" +wait |