diff options
Diffstat (limited to 'mirror.sh')
-rw-r--r-- | mirror.sh | 38 |
1 files changed, 35 insertions, 3 deletions
@@ -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} |