Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit bd62fd1

Browse files
authored
Merge pull request #1533 from AstromechZA/aza_dep_install_script
Install.sh script for dep
2 parents 06d5271 + 8383253 commit bd62fd1

File tree

3 files changed

+166
-0
lines changed

3 files changed

+166
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ IMPROVEMENTS:
1010

1111
# v0.4.1
1212

13+
NEW FEATURES:
14+
15+
* Added `install.sh` script. ([#1533](https://github.com/golang/dep/pull/1533))
16+
1317
BUG FIXES:
1418

1519
* Fix per-project prune option handling ([#1570](https://github.com/golang/dep/pull/1570))
1620

1721
# v0.4.0
1822

1923
NEW FEATURES:
24+
2025
* Absorb `dep prune` into `dep ensure`. ([#944](https://github.com/golang/dep/issues/944))
2126
* Add support for importing from [glock](https://github.com/robfig/glock) based projects. ([#1422](https://github.com/golang/dep/pull/1422))
2227
* Add support for importing from [govendor](https://github.com/kardianos/govendor) based projects. ([#815](https://github.com/golang/dep/pull/815))

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ $ brew install dep
2424
$ brew upgrade dep
2525
```
2626

27+
On other platforms you can use the `install.sh` script:
28+
29+
```sh
30+
$ curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
31+
```
32+
33+
It will install into your `$GOPATH/bin` directory by default or any other directory you specify using the `INSTALL_DIRECTORY` environment variable.
34+
35+
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
36+
to the release builds.
37+
2738
If you're interested in hacking on `dep`, you can install via `go get`:
2839

2940
```sh

install.sh

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#!/bin/sh
2+
3+
# This install script is intended to download and install the latest available
4+
# release of the dep dependency manager for Golang.
5+
#
6+
# It attempts to identify the current platform and an error will be thrown if
7+
# the platform is not supported.
8+
#
9+
# Environment variables:
10+
# - INSTALL_DIRECTORY (optional): defaults to $GOPATH/bin
11+
# - DEP_RELEASE_TAG (optional): defaults to fetching the latest release
12+
# - DEP_OS (optional): use a specific value for OS (mostly for testing)
13+
# - DEP_ARCH (optional): use a specific value for ARCH (mostly for testing)
14+
#
15+
# You can install using this script:
16+
# $ curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
17+
18+
set -e
19+
20+
RELEASES_URL="https://github.com/golang/dep/releases"
21+
22+
downloadJSON() {
23+
url="$2"
24+
25+
echo "Fetching $url.."
26+
if type curl > /dev/null; then
27+
response=$(curl -s -L -w 'HTTPSTATUS:%{http_code}' -H 'Accept: application/json' "$url")
28+
body=$(echo "$response" | sed -e 's/HTTPSTATUS\:.*//g')
29+
code=$(echo "$response" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
30+
elif type wget > /dev/null; then
31+
temp=$(mktemp)
32+
body=$(wget -q --header='Accept: application/json' -O - --server-response --content-on-error "$url" 2> "$temp")
33+
code=$(awk '/^ HTTP/{print $2}' < "$temp")
34+
else
35+
echo "Neither curl nor wget was available to perform http requests."
36+
exit 1
37+
fi
38+
if [ "$code" != 200 ]; then
39+
echo "Request failed with code $code"
40+
exit 1
41+
fi
42+
43+
eval "$1='$body'"
44+
}
45+
46+
downloadFile() {
47+
url="$1"
48+
destination="$2"
49+
50+
echo "Fetching $url.."
51+
if type curl > /dev/null; then
52+
code=$(curl -s -w '%{http_code}' -L "$url" -o "$destination")
53+
elif type wget > /dev/null; then
54+
code=$(wget -q -O "$destination" --server-response "$url" 2>&1 | awk '/^ HTTP/{print $2}')
55+
else
56+
echo "Neither curl nor wget was available to perform http requests."
57+
exit 1
58+
fi
59+
60+
if [ "$code" != 200 ]; then
61+
echo "Request failed with code $code"
62+
exit 1
63+
fi
64+
}
65+
66+
findGoBinDirectory() {
67+
if [ -z "$GOPATH" ]; then
68+
echo "Installation requires \$GOPATH to be set for your Golang environment."
69+
exit 1
70+
fi
71+
if [ -z "$GOBIN" ]; then
72+
GOBIN="$GOPATH/bin"
73+
fi
74+
if [ ! -d "$GOBIN" ]; then
75+
echo "Installation requires your GOBIN directory $GOBIN to exist. Please create it."
76+
exit 1
77+
fi
78+
eval "$1='$GOBIN'"
79+
}
80+
81+
initArch() {
82+
ARCH=$(uname -m)
83+
if [ -n "$DEP_ARCH" ]; then
84+
echo "Using DEP_ARCH"
85+
ARCH="$DEP_ARCH"
86+
fi
87+
case $ARCH in
88+
amd64) ARCH="amd64";;
89+
x86_64) ARCH="amd64";;
90+
i386) ARCH="386";;
91+
*) echo "Architecture ${ARCH} is not supported by this installation script"; exit 1;;
92+
esac
93+
echo "ARCH = $ARCH"
94+
}
95+
96+
initOS() {
97+
OS=$(uname | tr '[:upper:]' '[:lower:]')
98+
if [ -n "$DEP_OS" ]; then
99+
echo "Using DEP_OS"
100+
OS="$DEP_OS"
101+
fi
102+
case "$OS" in
103+
darwin) OS='darwin';;
104+
linux) OS='linux';;
105+
freebsd) OS='freebsd';;
106+
mingw*) OS='windows';;
107+
msys*) OS='windows';;
108+
*) echo "OS ${OS} is not supported by this installation script"; exit 1;;
109+
esac
110+
echo "OS = $OS"
111+
}
112+
113+
# identify platform based on uname output
114+
initArch
115+
initOS
116+
117+
# determine install directory if required
118+
if [ -z "$INSTALL_DIRECTORY" ]; then
119+
findGoBinDirectory INSTALL_DIRECTORY
120+
fi
121+
echo "Will install into $INSTALL_DIRECTORY"
122+
123+
# assemble expected release artifact name
124+
BINARY="dep-${OS}-${ARCH}"
125+
126+
# add .exe if on windows
127+
if [ "$OS" = "windows" ]; then
128+
BINARY="$BINARY.exe"
129+
fi
130+
131+
# if DEP_RELEASE_TAG was not provided, assume latest
132+
if [ -z "$DEP_RELEASE_TAG" ]; then
133+
downloadJSON LATEST_RELEASE "$RELEASES_URL/latest"
134+
DEP_RELEASE_TAG=$(echo "${LATEST_RELEASE}" | tr -s '\n' ' ' | sed 's/.*"tag_name":"//' | sed 's/".*//' )
135+
fi
136+
echo "Release Tag = $DEP_RELEASE_TAG"
137+
138+
# fetch the real release data to make sure it exists before we attempt a download
139+
downloadJSON RELEASE_DATA "$RELEASES_URL/tag/$DEP_RELEASE_TAG"
140+
141+
BINARY_URL="$RELEASES_URL/download/$DEP_RELEASE_TAG/$BINARY"
142+
DOWNLOAD_FILE=$(mktemp)
143+
144+
downloadFile "$BINARY_URL" "$DOWNLOAD_FILE"
145+
146+
echo "Setting executable permissions."
147+
chmod +x "$DOWNLOAD_FILE"
148+
149+
echo "Moving executable to $INSTALL_DIRECTORY/dep"
150+
mv "$DOWNLOAD_FILE" "$INSTALL_DIRECTORY/dep"

0 commit comments

Comments
 (0)