|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +set -o errexit |
| 4 | +set -o nounset |
| 5 | + |
| 6 | +ROOT="$(git rev-parse --show-toplevel)" |
| 7 | +DEPENDENCIES="$ROOT/DEPENDENCIES" |
| 8 | + |
| 9 | +fail() { |
| 10 | + echo "$1" 1>&2 |
| 11 | + exit 1 |
| 12 | +} |
| 13 | + |
| 14 | +log() { |
| 15 | + echo "-- $1" 1>&2 |
| 16 | +} |
| 17 | + |
| 18 | +if [ ! -f "$DEPENDENCIES" ] |
| 19 | +then |
| 20 | + fail "File not found: $DEPENDENCIES" |
| 21 | +fi |
| 22 | + |
| 23 | +DEPENDENCY="${1-}" |
| 24 | +if [ -z "$DEPENDENCY" ] |
| 25 | +then |
| 26 | + fail "Usage: $0 <dependency>" |
| 27 | +fi |
| 28 | + |
| 29 | +LINE="$(grep "^$DEPENDENCY " < "$DEPENDENCIES" || true)" |
| 30 | +if [ -z "$LINE" ] |
| 31 | +then |
| 32 | + fail "Unknown dependency: $DEPENDENCY" |
| 33 | +fi |
| 34 | + |
| 35 | +NAME="$(echo "$LINE" | cut -d ' ' -f 1)" |
| 36 | +URL="$(echo "$LINE" | cut -d ' ' -f 2)" |
| 37 | +VERSION="$(echo "$LINE" | cut -d ' ' -f 3)" |
| 38 | +if [ -z "$NAME" ] || [ -z "$URL" ] || [ -z "$VERSION" ] |
| 39 | +then |
| 40 | + fail "Invalid dependency definition: $DEPENDENCY" |
| 41 | +fi |
| 42 | + |
| 43 | +TMP="$(mktemp -d -t vendorpull-clone-XXXXX)" |
| 44 | +log "Setting up temporary directory at $TMP..." |
| 45 | +clean() { rm -rf "$TMP"; } |
| 46 | +trap clean EXIT |
| 47 | + |
| 48 | +log "Fetching the tip of $URL into $TMP/$NAME" |
| 49 | +git clone --depth 1 --jobs 8 "$URL" "$TMP/$NAME" |
| 50 | + |
| 51 | +# Try to determine the tag, otherwise the commit hash |
| 52 | +NEW_VERSION="$(git -C "$TMP/$NAME" describe --tags --exact-match HEAD 2>/dev/null \ |
| 53 | + || git -C "$TMP/$NAME" rev-parse HEAD)" |
| 54 | + |
| 55 | +log "Upgrading $NAME to $NEW_VERSION" |
| 56 | +awk -v name="$NAME" -v version="$NEW_VERSION" \ |
| 57 | + '$1 == name {$3 = version} {print}' \ |
| 58 | + DEPENDENCIES > "$TMP/DEPENDENCIES" |
| 59 | + |
| 60 | +mv "$TMP/DEPENDENCIES" "$DEPENDENCIES" |
| 61 | +git diff "$DEPENDENCIES" |
0 commit comments