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

Commit 283c00c

Browse files
committed
Added .exe suffix for windows binary; Added DEP_FAKE_* variables for testing and unusual scenarios
1 parent aa9d47c commit 283c00c

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

Diff for: install.sh

+33-18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# Environment variables:
1010
# - INSTALL_DIRECTORY (optional): defaults to $GOPATH/bin
1111
# - DEP_RELEASE_TAG (optional): defaults to fetching the latest release
12+
# - DEP_FAKE_OS (optional): use a fake value for OS (mostly for testing)
13+
# - DEP_FAKE_ARCH (optional): use a fake value for ARCH (mostly for testing)
1214
#
1315
# You can install using this script:
1416
# $ curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
@@ -34,9 +36,9 @@ downloadJSON() {
3436
exit 1
3537
fi
3638
if [ "$code" != 200 ]; then
37-
echo "Request failed with code $code"
38-
exit 1
39-
fi
39+
echo "Request failed with code $code"
40+
exit 1
41+
fi
4042

4143
eval "$1='$body'"
4244
}
@@ -56,9 +58,9 @@ downloadFile() {
5658
fi
5759

5860
if [ "$code" != 200 ]; then
59-
echo "Request failed with code $code"
60-
exit 1
61-
fi
61+
echo "Request failed with code $code"
62+
exit 1
63+
fi
6264
}
6365

6466
findGoBinDirectory() {
@@ -77,34 +79,42 @@ findGoBinDirectory() {
7779
}
7880

7981
initArch() {
80-
ARCH=$(uname -m)
81-
case $ARCH in
82+
ARCH=$(uname -m)
83+
if [ -n "$DEP_FAKE_ARCH" ]; then
84+
echo "Using DEP_FAKE_ARCH"
85+
ARCH="$DEP_FAKE_ARCH"
86+
fi
87+
case $ARCH in
8288
amd64) ARCH="amd64";;
83-
x86_64) ARCH="amd64";;
89+
x86_64) ARCH="amd64";;
8490
i386) ARCH="386";;
8591
*) echo "Architecture ${ARCH} is not supported by this installation script"; exit 1;;
86-
esac
87-
echo "ARCH = $ARCH"
92+
esac
93+
echo "ARCH = $ARCH"
8894
}
8995

9096
initOS() {
91-
OS=$(uname | tr '[:upper:]' '[:lower:]')
92-
93-
case "$OS" in
97+
OS=$(uname | tr '[:upper:]' '[:lower:]')
98+
if [ -n "$DEP_FAKE_OS" ]; then
99+
echo "Using DEP_FAKE_OS"
100+
OS="$DEP_FAKE_OS"
101+
fi
102+
case "$OS" in
94103
darwin) OS='darwin';;
95104
linux) OS='linux';;
96105
freebsd) OS='freebsd';;
97-
mingw*) OS='windows';;
98-
msys*) OS='windows';;
106+
mingw*) OS='windows';;
107+
msys*) OS='windows';;
99108
*) echo "OS ${OS} is not supported by this installation script"; exit 1;;
100-
esac
101-
echo "OS = $OS"
109+
esac
110+
echo "OS = $OS"
102111
}
103112

104113
# identify platform based on uname output
105114
initArch
106115
initOS
107116

117+
# determine install directory if required
108118
if [ -z "$INSTALL_DIRECTORY" ]; then
109119
findGoBinDirectory INSTALL_DIRECTORY
110120
fi
@@ -113,6 +123,11 @@ echo "Will install into $INSTALL_DIRECTORY"
113123
# assemble expected release artifact name
114124
BINARY="dep-${OS}-${ARCH}"
115125

126+
# add .exe if on windows
127+
if [ "$OS" = "windows" ]; then
128+
BINARY="$BINARY.exe"
129+
fi
130+
116131
# if DEP_RELEASE_TAG was not provided, assume latest
117132
if [ -z "$DEP_RELEASE_TAG" ]; then
118133
downloadJSON LATEST_RELEASE "$RELEASES_URL/latest"

0 commit comments

Comments
 (0)