summaryrefslogtreecommitdiff
path: root/mirror.sh
diff options
context:
space:
mode:
Diffstat (limited to 'mirror.sh')
-rw-r--r--mirror.sh38
1 files changed, 35 insertions, 3 deletions
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}