1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#!/usr/bin/env bash
#
# This script updates dependencies using a temporary directory. This is required
# to avoid any auxillary dependencies that sneak into GOPATH.
set -e
# Get the parent directory of where this script is.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
DIR="$(cd -P "$(dirname "$SOURCE")/.." && pwd)"
# Change into that directory
cd "$DIR"
# Get the name from the directory
NAME=${NAME:-"$(basename $(pwd))"}
# Announce
echo "==> Updating dependencies..."
echo "--> Making tmpdir..."
tmpdir=$(mktemp -d)
function cleanup {
rm -rf "${tmpdir}"
}
trap cleanup EXIT
export GOPATH="${tmpdir}"
export PATH="${tmpdir}/bin:$PATH"
mkdir -p "${tmpdir}/src/github.com/hashicorp"
pushd "${tmpdir}/src/github.com/hashicorp" &>/dev/null
echo "--> Copying ${NAME}..."
cp -R "$DIR" "${tmpdir}/src/github.com/hashicorp/${NAME}"
pushd "${tmpdir}/src/github.com/hashicorp/${NAME}" &>/dev/null
rm -rf vendor/
echo "--> Installing dependency manager..."
go get -u github.com/kardianos/govendor
govendor init
echo "--> Installing all dependencies (may take some time)..."
govendor fetch -v +outside
echo "--> Vendoring..."
govendor add +external
echo "--> Moving into place..."
vpath="${tmpdir}/src/github.com/hashicorp/${NAME}/vendor"
popd &>/dev/null
popd &>/dev/null
rm -rf vendor/
cp -R "${vpath}" .
|