summaryrefslogtreecommitdiff
path: root/pbs-plumb-download
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2012-11-01 02:20:42 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2012-11-01 02:20:42 -0400
commitc1c7f3a2516b1101cae844e2506ef8aace5cca29 (patch)
treeec85341767969d108ff44a609aa5a63cbae29a47 /pbs-plumb-download
initial commit
Diffstat (limited to 'pbs-plumb-download')
-rwxr-xr-xpbs-plumb-download36
1 files changed, 36 insertions, 0 deletions
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 "$@"