From c1c7f3a2516b1101cae844e2506ef8aace5cca29 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 1 Nov 2012 02:20:42 -0400 Subject: initial commit --- pbs-plumb-download | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 pbs-plumb-download (limited to 'pbs-plumb-download') diff --git a/pbs-plumb-download b/pbs-plumb-download new file mode 100755 index 0000000..8d4abf2 --- /dev/null +++ b/pbs-plumb-download @@ -0,0 +1,36 @@ +#!/bin/bash -e + +. /usr/bin/libremessages + +main() { + [[ $# != 1 ]] && { usage; return 1; } + local source=$1 + local url="$(pbs-plumb-config get "source.$source.url")" + + local cachedir="$(pbs-plumb-config get core.cachedir)" + [[ -d "${cachedir}" ]] || mkdir -p "${cachedir}" + + if [[ ! -d "${cachedir}/${source}.git" ]]; then + cd "${cachedir}" + msg "$(gettext "Cloning %s")" "${cachedir}/${source}.git" + if ! git clone --mirror "$url" "$source.git"; then + error "$(gettext "Failed to download source %s")" "$source" + exit 1 + fi + else + cd "${cachedir}/${source}.git" + # Make sure we are fetching the right repo + if [[ "$url" != "$(git config --get remote.origin.url)" ]] ; then + error "$(gettext "%s is not a clone of %s")" "$source" "$url" + plain "$(gettext "Aborting...")" + exit 1 + fi + msg "$(gettext "Updating %s")" "${cachedir}/${source}.git" + if ! git fetch --all -p; then + error "$(gettext "Failed to update source %s")" "$source" + exit 1 + fi + fi +} + +main "$@" -- cgit v1.2.3