This repository has been archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
Install.sh script for dep #1533
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
#!/bin/sh | ||
|
||
# This install script is intended to download and install the latest available | ||
# release of the dep dependency manager for Golang. | ||
# | ||
# It attempts to identify the current platform and an error will be thrown if | ||
# the platform is not supported. | ||
# | ||
# Environment variables: | ||
# - INSTALL_DIRECTORY (optional): defaults to $GOPATH/bin | ||
# - 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: | ||
# $ curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh | ||
|
||
set -e | ||
|
||
RELEASES_URL="https://github.com/golang/dep/releases" | ||
|
||
downloadJSON() { | ||
url="$2" | ||
|
||
echo "Fetching $url.." | ||
if type curl > /dev/null; then | ||
response=$(curl -s -L -w 'HTTPSTATUS:%{http_code}' -H 'Accept: application/json' "$url") | ||
body=$(echo "$response" | sed -e 's/HTTPSTATUS\:.*//g') | ||
code=$(echo "$response" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://') | ||
elif type wget > /dev/null; then | ||
temp=$(mktemp) | ||
body=$(wget -q --header='Accept: application/json' -O - --server-response --content-on-error "$url" 2> "$temp") | ||
code=$(awk '/^ HTTP/{print $2}' < "$temp") | ||
else | ||
echo "Neither curl nor wget was available to perform http requests." | ||
exit 1 | ||
fi | ||
if [ "$code" != 200 ]; then | ||
echo "Request failed with code $code" | ||
exit 1 | ||
fi | ||
|
||
eval "$1='$body'" | ||
} | ||
|
||
downloadFile() { | ||
url="$1" | ||
destination="$2" | ||
|
||
echo "Fetching $url.." | ||
if type curl > /dev/null; then | ||
code=$(curl -s -w '%{http_code}' -L "$url" -o "$destination") | ||
elif type wget > /dev/null; then | ||
code=$(wget -q -O "$destination" --server-response "$url" 2>&1 | awk '/^ HTTP/{print $2}') | ||
else | ||
echo "Neither curl nor wget was available to perform http requests." | ||
exit 1 | ||
fi | ||
|
||
if [ "$code" != 200 ]; then | ||
echo "Request failed with code $code" | ||
exit 1 | ||
fi | ||
} | ||
|
||
findGoBinDirectory() { | ||
if [ -z "$GOPATH" ]; then | ||
echo "Installation requires \$GOPATH to be set for your Golang environment." | ||
exit 1 | ||
fi | ||
if [ -z "$GOBIN" ]; then | ||
GOBIN="$GOPATH/bin" | ||
fi | ||
if [ ! -d "$GOBIN" ]; then | ||
echo "Installation requires your GOBIN directory $GOBIN to exist. Please create it." | ||
exit 1 | ||
fi | ||
eval "$1='$GOBIN'" | ||
} | ||
|
||
initArch() { | ||
ARCH=$(uname -m) | ||
if [ -n "$DEP_FAKE_ARCH" ]; then | ||
echo "Using DEP_FAKE_ARCH" | ||
ARCH="$DEP_FAKE_ARCH" | ||
fi | ||
case $ARCH in | ||
amd64) ARCH="amd64";; | ||
x86_64) ARCH="amd64";; | ||
i386) ARCH="386";; | ||
*) echo "Architecture ${ARCH} is not supported by this installation script"; exit 1;; | ||
esac | ||
echo "ARCH = $ARCH" | ||
} | ||
|
||
initOS() { | ||
OS=$(uname | tr '[:upper:]' '[:lower:]') | ||
if [ -n "$DEP_FAKE_OS" ]; then | ||
echo "Using DEP_FAKE_OS" | ||
OS="$DEP_FAKE_OS" | ||
fi | ||
case "$OS" in | ||
darwin) OS='darwin';; | ||
linux) OS='linux';; | ||
freebsd) OS='freebsd';; | ||
mingw*) OS='windows';; | ||
msys*) OS='windows';; | ||
*) echo "OS ${OS} is not supported by this installation script"; exit 1;; | ||
esac | ||
echo "OS = $OS" | ||
} | ||
|
||
# identify platform based on uname output | ||
initArch | ||
initOS | ||
|
||
# determine install directory if required | ||
if [ -z "$INSTALL_DIRECTORY" ]; then | ||
findGoBinDirectory INSTALL_DIRECTORY | ||
fi | ||
echo "Will install into $INSTALL_DIRECTORY" | ||
|
||
# assemble expected release artifact name | ||
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 [ -z "$DEP_RELEASE_TAG" ]; then | ||
downloadJSON LATEST_RELEASE "$RELEASES_URL/latest" | ||
DEP_RELEASE_TAG=$(echo "${LATEST_RELEASE}" | tr -s '\n' ' ' | sed 's/.*"tag_name":"//' | sed 's/".*//' ) | ||
fi | ||
echo "Release Tag = $DEP_RELEASE_TAG" | ||
|
||
# fetch the real release data to make sure it exists before we attempt a download | ||
downloadJSON RELEASE_DATA "$RELEASES_URL/tag/$DEP_RELEASE_TAG" | ||
|
||
BINARY_URL="$RELEASES_URL/download/$DEP_RELEASE_TAG/$BINARY" | ||
DOWNLOAD_FILE=$(mktemp) | ||
|
||
downloadFile "$BINARY_URL" "$DOWNLOAD_FILE" | ||
|
||
echo "Setting executable permissions." | ||
chmod +x "$DOWNLOAD_FILE" | ||
|
||
echo "Moving executable to $INSTALL_DIRECTORY/dep" | ||
mv "$DOWNLOAD_FILE" "$INSTALL_DIRECTORY/dep" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nit: can we use
DEP_OS
andDEP_ARCH
instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will push an update just now.