Added .exe suffix for windows binary; Added DEP_FAKE_* variables for testing and unusual scenarios

This commit is contained in:
Ben Meier 2018-01-28 07:36:47 +02:00
Родитель e0bb5ac8ff
Коммит 4f2a7ab76f
1 изменённых файлов: 33 добавлений и 18 удалений

Просмотреть файл

@ -9,6 +9,8 @@
# Environment variables: # Environment variables:
# - INSTALL_DIRECTORY (optional): defaults to $GOPATH/bin # - INSTALL_DIRECTORY (optional): defaults to $GOPATH/bin
# - DEP_RELEASE_TAG (optional): defaults to fetching the latest release # - DEP_RELEASE_TAG (optional): defaults to fetching the latest release
# - DEP_FAKE_OS (optional): use a fake value for OS (mostly for testing)
# - DEP_FAKE_ARCH (optional): use a fake value for ARCH (mostly for testing)
# #
# You can install using this script: # You can install using this script:
# $ curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh # $ curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
@ -34,9 +36,9 @@ downloadJSON() {
exit 1 exit 1
fi fi
if [ "$code" != 200 ]; then if [ "$code" != 200 ]; then
echo "Request failed with code $code" echo "Request failed with code $code"
exit 1 exit 1
fi fi
eval "$1='$body'" eval "$1='$body'"
} }
@ -56,9 +58,9 @@ downloadFile() {
fi fi
if [ "$code" != 200 ]; then if [ "$code" != 200 ]; then
echo "Request failed with code $code" echo "Request failed with code $code"
exit 1 exit 1
fi fi
} }
findGoBinDirectory() { findGoBinDirectory() {
@ -77,34 +79,42 @@ findGoBinDirectory() {
} }
initArch() { initArch() {
ARCH=$(uname -m) ARCH=$(uname -m)
case $ARCH in if [ -n "$DEP_FAKE_ARCH" ]; then
echo "Using DEP_FAKE_ARCH"
ARCH="$DEP_FAKE_ARCH"
fi
case $ARCH in
amd64) ARCH="amd64";; amd64) ARCH="amd64";;
x86_64) ARCH="amd64";; x86_64) ARCH="amd64";;
i386) ARCH="386";; i386) ARCH="386";;
*) echo "Architecture ${ARCH} is not supported by this installation script"; exit 1;; *) echo "Architecture ${ARCH} is not supported by this installation script"; exit 1;;
esac esac
echo "ARCH = $ARCH" echo "ARCH = $ARCH"
} }
initOS() { initOS() {
OS=$(uname | tr '[:upper:]' '[:lower:]') OS=$(uname | tr '[:upper:]' '[:lower:]')
if [ -n "$DEP_FAKE_OS" ]; then
case "$OS" in echo "Using DEP_FAKE_OS"
OS="$DEP_FAKE_OS"
fi
case "$OS" in
darwin) OS='darwin';; darwin) OS='darwin';;
linux) OS='linux';; linux) OS='linux';;
freebsd) OS='freebsd';; freebsd) OS='freebsd';;
mingw*) OS='windows';; mingw*) OS='windows';;
msys*) OS='windows';; msys*) OS='windows';;
*) echo "OS ${OS} is not supported by this installation script"; exit 1;; *) echo "OS ${OS} is not supported by this installation script"; exit 1;;
esac esac
echo "OS = $OS" echo "OS = $OS"
} }
# identify platform based on uname output # identify platform based on uname output
initArch initArch
initOS initOS
# determine install directory if required
if [ -z "$INSTALL_DIRECTORY" ]; then if [ -z "$INSTALL_DIRECTORY" ]; then
findGoBinDirectory INSTALL_DIRECTORY findGoBinDirectory INSTALL_DIRECTORY
fi fi
@ -113,6 +123,11 @@ echo "Will install into $INSTALL_DIRECTORY"
# assemble expected release artifact name # assemble expected release artifact name
BINARY="dep-${OS}-${ARCH}" BINARY="dep-${OS}-${ARCH}"
# add .exe if on windows
if [ "$OS" = "windows" ]; then
BINARY="$BINARY.exe"
fi
# if DEP_RELEASE_TAG was not provided, assume latest # if DEP_RELEASE_TAG was not provided, assume latest
if [ -z "$DEP_RELEASE_TAG" ]; then if [ -z "$DEP_RELEASE_TAG" ]; then
downloadJSON LATEST_RELEASE "$RELEASES_URL/latest" downloadJSON LATEST_RELEASE "$RELEASES_URL/latest"