forked from Masterminds/glide.sh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get
136 lines (119 loc) · 3.21 KB
/
get
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/sh
# The install script is licensed under the MIT license Glide itself is under.
# See https://github.com/Masterminds/glide/blob/master/LICENSE for more details.
# To run this script execute:
# `curl https://glide.sh/get | sh`
PROJECT_NAME="glide"
# LGOBIN represents the local bin location. This can be either the GOBIN, if set,
# or the GOPATH/bin.
LGOBIN=""
verifyGoInstallation() {
GO=$(which go)
if [ "$?" = "1" ]; then
echo "$PROJECT_NAME needs go. Please intall it first."
exit 1
fi
if [ -z "$GOPATH" ]; then
echo "$PROJECT_NAME needs environment variable "'$GOPATH'". Set it before continue."
exit 1
fi
if [ -n "$GOBIN" ]; then
if [ ! -d "$GOBIN" ]; then
echo "$GOBIN "'($GOBIN)'" folder not found. Please create it before continue."
exit 1
fi
LGOBIN="$GOBIN"
else
if [ ! -d "$GOPATH/bin" ]; then
echo "$GOPATH/bin "'($GOPATH/bin)'" folder not found. Please create it before continue."
exit 1
fi
LGOBIN="$GOPATH/bin"
fi
}
initArch() {
ARCH=$(uname -m)
case $ARCH in
armv5*) ARCH="armv5";;
armv6*) ARCH="armv6";;
armv7*) ARCH="armv7";;
aarch64) ARCH="arm64";;
x86) ARCH="386";;
x86_64) ARCH="amd64";;
i686) ARCH="386";;
i386) ARCH="386";;
esac
}
initOS() {
OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')
case "$OS" in
# Minimalist GNU for Windows
mingw*) OS='windows';;
esac
}
downloadFile() {
if type "curl" > /dev/null; then
TAG=$(curl -s https://glide.sh/version)
elif type "wget" > /dev/null; then
TAG=$(wget -q -O - https://glide.sh/version)
fi
LATEST_RELEASE_URL="https://api.github.com/repos/Masterminds/$PROJECT_NAME/releases/tags/$TAG"
if type "curl" > /dev/null; then
LATEST_RELEASE_JSON=$(curl -s "$LATEST_RELEASE_URL")
elif type "wget" > /dev/null; then
LATEST_RELEASE_JSON=$(wget -q -O - "$LATEST_RELEASE_URL")
fi
GLIDE_DIST="glide-$TAG-$OS-$ARCH.tar.gz"
# || true forces this command to not catch error if grep does not find anything
DOWNLOAD_URL=$(echo "$LATEST_RELEASE_JSON" | grep 'browser_' | cut -d\" -f4 | grep "$GLIDE_DIST") || true
if [ -z "$DOWNLOAD_URL" ]; then
echo "Sorry, we dont have a dist for your system: $OS $ARCH"
echo "You can ask one here: https://github.com/Masterminds/$PROJECT_NAME/issues"
exit 1
else
GLIDE_TMP_FILE="/tmp/$GLIDE_DIST"
echo "Downloading $DOWNLOAD_URL"
if type "curl" > /dev/null; then
curl -L "$DOWNLOAD_URL" -o "$GLIDE_TMP_FILE"
elif type "wget" > /dev/null; then
wget -q -O "$GLIDE_TMP_FILE" "$DOWNLOAD_URL"
fi
fi
}
installFile() {
GLIDE_TMP="/tmp/$PROJECT_NAME"
mkdir -p "$GLIDE_TMP"
tar xf "$GLIDE_TMP_FILE" -C "$GLIDE_TMP"
GLIDE_TMP_BIN="$GLIDE_TMP/$OS-$ARCH/$PROJECT_NAME"
cp "$GLIDE_TMP_BIN" "$LGOBIN"
rm -rf $GLIDE_TMP
rm -f $GLIDE_TMP_FILE
}
bye() {
result=$?
if [ "$result" != "0" ]; then
echo "Fail to install $PROJECT_NAME"
fi
exit $result
}
testVersion() {
set +e
GLIDE="$(which $PROJECT_NAME)"
if [ "$?" = "1" ]; then
echo "$PROJECT_NAME not found. Did you add "'$LGOBIN'" to your "'$PATH?'
exit 1
fi
set -e
GLIDE_VERSION=$($PROJECT_NAME -v)
echo "$GLIDE_VERSION installed succesfully"
}
# Execution
#Stop execution on any error
trap "bye" EXIT
verifyGoInstallation
set -e
initArch
initOS
downloadFile
installFile
testVersion