From a690ee5ab819ef03176194b044a6854b2a07e1ab Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 28 Dec 2023 14:32:06 +0100 Subject: A non-zero exit status will be returned on one or more failure Tool will now use date-based versioning scheme: '%Y%m%d.N', where N will get incremented if multiple releases happen during a day. This is not done automatically currently. Some additional smaller changes were done to support exit status and versioning. --- mirror.sh | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'mirror.sh') diff --git a/mirror.sh b/mirror.sh index 4ded042..49a3057 100644 --- a/mirror.sh +++ b/mirror.sh @@ -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} -- cgit v1.1