diff options
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | mirror.1 | 12 | ||||
-rw-r--r-- | mirror.sh | 38 |
3 files changed, 54 insertions, 8 deletions
@@ -1,13 +1,19 @@ +TODAY=1 PREFIX?=/usr/local BINDIR?=$(PREFIX)/bin DATADIR?=$(PREFIX)/share -MANDIR?=$(DATADIR)/man/man1 +MANDIR?=$(DATADIR)/man +MAN1DIR?=$(MANDIR)/man1 LIBDIR?=$(PREFIX)/lib SYSDDIR?=$(LIBDIR)/systemd/system USERSDIR?=$(LIBDIR)/sysusers.d all: mirror +%: %.sh + sed s/@VERSION@/`git rev-list -1 --date=format:%Y%m%d --pretty=%ad --no-commit-header HEAD`.$(TODAY)/g <$< >$@ + chmod +x $@ + clean: rm -f mirror @@ -17,14 +23,14 @@ install: all mkdir -p $(DESTDIR)$(SYSDDIR) mkdir -p $(DESTDIR)$(USERSDIR) cp -f mirror $(DESTDIR)$(BINDIR)/mirror - cp -f mirror.1 $(DESTDIR)$(MANDIR)/mirror.1 + cp -f mirror.1 $(DESTDIR)$(MAN1DIR)/mirror.1 cp -f mirror.timer $(DESTDIR)$(SYSDDIR)/mirror.timer cp -f mirror.service $(DESTDIR)$(SYSDDIR)/mirror.service cp -f mirror.conf $(DESTDIR)$(USERSDIR)/mirror.conf uninstall: rm -f $(DESTDIR)$(BINDIR)/mirror - rm -f $(DESTDIR)$(MANDIR)/mirror.1 + rm -f $(DESTDIR)$(MAN1DIR)/mirror.1 rm -f $(DESTDIR)$(SYSDDIR)/mirror.timer rm -f $(DESTDIR)$(SYSDDIR)/mirror.service rm -f $(DESTDIR)$(USERSDIR)/mirror.conf @@ -1,9 +1,10 @@ -.TH mirror 1 "2023-04-15" +.TH mirror 1 "2023-12-28" .SH NAME mirror \- copies remote git repositories in bulk .SH SYNOPSIS .SY mirror .RI [ list ] +.SY mirror\ -v .YS .SH DESCRIPTION This script will read @@ -14,7 +15,14 @@ provided will default to .B repositories.list in the current working directory. +.P +With +.B -v +option the script will print version information to standard output and terminate immediately after. .SH EXIT STATUS -Script is not expected to provide a useful exit status as of now. +Exit status is zero if all repositories in the list have been mirrored successfully or if +.B -v +option was used. If one or more mirrors fail or an unknown command-line option is provided, a non-zero status is +returned. .SH SEE ALSO .BR git (1) @@ -1,4 +1,16 @@ #!/bin/sh +_version() { + echo "@VERSION@" + exit 0 +} + + +_usage() { + echo "Usage: $0 [-v] [list]" + exit 1 +} >&2 + + _path() { local path="$(url %h%p $1)" case "${path}" in @@ -11,14 +23,34 @@ _path() { _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}" + test -d "${path}" || git clone -q --mirror "${repo}" "${path}" || return 1 # TODO: Check if remotes are the same? + if git -C "${path}" fetch -q; then + echo "Updated ${path}" + else + echo "Failed to update ${path}" >&2 + return 1 + fi } +while getopts :v opt; do + case ${opt} in + v) _version;; + ?) _usage;; + esac +done +shift $(( ${OPTIND} - 1 )) list="${1:-repositories.list}" test -f "${list}" || exit 1 +pids= while read repo; do _update "${repo}" & + pids="${pids} $!" done <"${list}" -wait +failed=0 +for pid in ${pids}; do + if ! wait ${pid}; then + failed=1 + fi +done +exit ${failed} |