#!/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 *.git) echo "${path}";; *) echo "${path}.git";; esac } _update() { local repo="$1" local path="$(_path ${repo})" 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}" failed=0 for pid in ${pids}; do if ! wait ${pid}; then failed=1 fi done exit ${failed}