From e0bb5ac8ff9fd62bba6c2c6e384b64e8a925f1c7 Mon Sep 17 00:00:00 2001 From: Ben Meier Date: Fri, 26 Jan 2018 00:04:53 +0200 Subject: [PATCH 1/3] Added install.sh script; Changelog entry; Changelog parenths fixes; REAMDE addition --- CHANGELOG.md | 5 ++ README.md | 11 +++++ install.sh | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 install.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b741b3bab..673d808646 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ IMPROVEMENTS: # v0.4.1 +NEW FEATURES: + +* Added `install.sh` script. ([#1533](https://github.com/golang/dep/pull/1533)) + BUG FIXES: * Fix per-project prune option handling ([#1570](https://github.com/golang/dep/pull/1570)) @@ -15,6 +19,7 @@ BUG FIXES: # v0.4.0 NEW FEATURES: + * Absorb `dep prune` into `dep ensure`. ([#944](https://github.com/golang/dep/issues/944)) * Add support for importing from [glock](https://github.com/robfig/glock) based projects. ([#1422](https://github.com/golang/dep/pull/1422)) * Add support for importing from [govendor](https://github.com/kardianos/govendor) based projects. ([#815](https://github.com/golang/dep/pull/815)) diff --git a/README.md b/README.md index 49e407dfda..0102c8d829 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,17 @@ $ brew install dep $ brew upgrade dep ``` +On other platforms you can use the `install.sh` script: + +```sh +$ curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh +``` + +It will install into your `$GOPATH/bin` directory by default or any other directory you specify using the `INSTALL_DIRECTORY` environment variable. + +If your platform is not supported, you'll need to build it manually or let the team know and we'll consider adding your platform +to the release builds. + If you're interested in hacking on `dep`, you can install via `go get`: ```sh diff --git a/install.sh b/install.sh new file mode 100644 index 0000000000..20757ec702 --- /dev/null +++ b/install.sh @@ -0,0 +1,135 @@ +#!/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 +# +# 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) + 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:]') + + 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 + +if [ -z "$INSTALL_DIRECTORY" ]; then + findGoBinDirectory INSTALL_DIRECTORY +fi +echo "Will install into $INSTALL_DIRECTORY" + +# assemble expected release artifact name +BINARY="dep-${OS}-${ARCH}" + +# 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" From 4f2a7ab76feba6a6600aa50fa9eabfb544fb9a8c Mon Sep 17 00:00:00 2001 From: Ben Meier Date: Sun, 28 Jan 2018 07:36:47 +0200 Subject: [PATCH 2/3] Added .exe suffix for windows binary; Added DEP_FAKE_* variables for testing and unusual scenarios --- install.sh | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/install.sh b/install.sh index 20757ec702..b19b901992 100644 --- a/install.sh +++ b/install.sh @@ -9,6 +9,8 @@ # 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 @@ -34,9 +36,9 @@ downloadJSON() { exit 1 fi if [ "$code" != 200 ]; then - echo "Request failed with code $code" - exit 1 - fi + echo "Request failed with code $code" + exit 1 + fi eval "$1='$body'" } @@ -56,9 +58,9 @@ downloadFile() { fi if [ "$code" != 200 ]; then - echo "Request failed with code $code" - exit 1 - fi + echo "Request failed with code $code" + exit 1 + fi } findGoBinDirectory() { @@ -77,34 +79,42 @@ findGoBinDirectory() { } initArch() { - ARCH=$(uname -m) - case $ARCH in + 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";; + x86_64) ARCH="amd64";; i386) ARCH="386";; *) echo "Architecture ${ARCH} is not supported by this installation script"; exit 1;; - esac - echo "ARCH = $ARCH" + esac + echo "ARCH = $ARCH" } initOS() { - OS=$(uname | tr '[:upper:]' '[:lower:]') - - case "$OS" in + 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';; + mingw*) OS='windows';; + msys*) OS='windows';; *) echo "OS ${OS} is not supported by this installation script"; exit 1;; - esac - echo "OS = $OS" + 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 @@ -113,6 +123,11 @@ 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" From 83832536eb421a577ef0c6ffd558d6e36ee6d79d Mon Sep 17 00:00:00 2001 From: Ben Meier Date: Fri, 2 Feb 2018 08:26:26 +0200 Subject: [PATCH 3/3] Removed FAKE from install.sh os/arch overrides --- install.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/install.sh b/install.sh index b19b901992..10ac341305 100644 --- a/install.sh +++ b/install.sh @@ -9,8 +9,8 @@ # 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) +# - DEP_OS (optional): use a specific value for OS (mostly for testing) +# - DEP_ARCH (optional): use a specific value for ARCH (mostly for testing) # # You can install using this script: # $ curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh @@ -80,9 +80,9 @@ findGoBinDirectory() { initArch() { ARCH=$(uname -m) - if [ -n "$DEP_FAKE_ARCH" ]; then - echo "Using DEP_FAKE_ARCH" - ARCH="$DEP_FAKE_ARCH" + if [ -n "$DEP_ARCH" ]; then + echo "Using DEP_ARCH" + ARCH="$DEP_ARCH" fi case $ARCH in amd64) ARCH="amd64";; @@ -95,9 +95,9 @@ initArch() { initOS() { OS=$(uname | tr '[:upper:]' '[:lower:]') - if [ -n "$DEP_FAKE_OS" ]; then - echo "Using DEP_FAKE_OS" - OS="$DEP_FAKE_OS" + if [ -n "$DEP_OS" ]; then + echo "Using DEP_OS" + OS="$DEP_OS" fi case "$OS" in darwin) OS='darwin';;