Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 741fd17

Browse files
author
Ryan King
authored
make it easier to download and install (#36)
* make it easier to download and install Add a make target `install-tf` that builds and installs where terraform can find the plugin. Update download.sh to work with our changes in #34. * unzip -u
1 parent d120125 commit 741fd17

File tree

2 files changed

+41
-28
lines changed

2 files changed

+41
-28
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,9 @@ release-prerelease: check-release-prereqs build ## release to github as a 'pre-r
7373
git push
7474
git push --tags
7575
goreleaser release -f .goreleaser.prerelease.yml --debug --rm-dist
76-
.PHONY: release-prerelease
76+
.PHONY: release-prerelease
77+
78+
install-tf: build ## installs plugin where terraform can find it
79+
mkdir -p $(HOME)/.terraform.d/plugins
80+
cp ./$(BASE_BINARY_NAME) $(HOME)/.terraform.d/plugins/$(BASE_BINARY_NAME)
81+
.PHONY: install-tf

download.sh

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22
set -e
3-
# Code generated by godownloader on 2019-12-05T18:58:14Z. DO NOT EDIT.
3+
# Code generated by godownloader on 2019-02-06T21:15:11Z. DO NOT EDIT.
44
#
55

66
usage() {
@@ -27,12 +27,11 @@ parse_args() {
2727
# over-ridden by flag below
2828

2929
BINDIR=${BINDIR:-./bin}
30-
while getopts "b:dh?x" arg; do
30+
while getopts "b:dh?" arg; do
3131
case "$arg" in
3232
b) BINDIR="$OPTARG" ;;
3333
d) log_set_priority 10 ;;
3434
h | \?) usage "$0" ;;
35-
x) set -x ;;
3635
esac
3736
done
3837
shift $((OPTIND - 1))
@@ -43,33 +42,39 @@ parse_args() {
4342
# network, either nothing will happen or will syntax error
4443
# out preventing half-done work
4544
execute() {
46-
tmpdir=$(mktemp -d)
45+
tmpdir=$(mktmpdir)
4746
log_debug "downloading files into ${tmpdir}"
4847
http_download "${tmpdir}/${TARBALL}" "${TARBALL_URL}"
4948
http_download "${tmpdir}/${CHECKSUM}" "${CHECKSUM_URL}"
5049
hash_sha256_verify "${tmpdir}/${TARBALL}" "${tmpdir}/${CHECKSUM}"
5150
srcdir="${tmpdir}"
5251
(cd "${tmpdir}" && untar "${TARBALL}")
53-
test ! -d "${BINDIR}" && install -d "${BINDIR}"
54-
for binexe in $BINARIES; do
52+
install -d "${BINDIR}"
53+
for binexe in "terraform-provider-bless_${TAG}" ; do
5554
if [ "$OS" = "windows" ]; then
5655
binexe="${binexe}.exe"
5756
fi
5857
install "${srcdir}/${binexe}" "${BINDIR}/"
5958
log_info "installed ${BINDIR}/${binexe}"
6059
done
61-
rm -rf "${tmpdir}"
6260
}
63-
get_binaries() {
64-
case "$PLATFORM" in
65-
darwin/amd64) BINARIES="terraform-provider-bless_{{ .Tag }}" ;;
66-
linux/amd64) BINARIES="terraform-provider-bless_{{ .Tag }}" ;;
67-
windows/amd64) BINARIES="terraform-provider-bless_{{ .Tag }}" ;;
68-
*)
69-
log_crit "platform $PLATFORM is not supported. Make sure this script is up-to-date and file request at https://github.com/${PREFIX}/issues/new"
70-
exit 1
71-
;;
61+
is_supported_platform() {
62+
platform=$1
63+
found=1
64+
case "$platform" in
65+
darwin/amd64) found=0 ;;
66+
linux/amd64) found=0 ;;
7267
esac
68+
return $found
69+
}
70+
check_platform() {
71+
if is_supported_platform "$PLATFORM"; then
72+
# optional logging goes here
73+
true
74+
else
75+
log_crit "platform $PLATFORM is not supported. Make sure this script is up-to-date and file request at https://github.com/${PREFIX}/issues/new"
76+
exit 1
77+
fi
7378
}
7479
tag_to_version() {
7580
if [ -z "${TAG}" ]; then
@@ -87,7 +92,7 @@ tag_to_version() {
8792
VERSION=${TAG#v}
8893
}
8994
adjust_format() {
90-
# change format (tar.gz or zip) based on OS
95+
# change format (tar.gz or zip) based on ARCH
9196
true
9297
}
9398
adjust_os() {
@@ -159,9 +164,7 @@ log_crit() {
159164
uname_os() {
160165
os=$(uname -s | tr '[:upper:]' '[:lower:]')
161166
case "$os" in
162-
cygwin_nt*) os="windows" ;;
163-
mingw*) os="windows" ;;
164-
msys_nt*) os="windows" ;;
167+
msys_nt) os="windows" ;;
165168
esac
166169
echo "$os"
167170
}
@@ -221,15 +224,20 @@ uname_arch_check() {
221224
untar() {
222225
tarball=$1
223226
case "${tarball}" in
224-
*.tar.gz | *.tgz) tar --no-same-owner -xzf "${tarball}" ;;
225-
*.tar) tar --no-same-owner -xf "${tarball}" ;;
226-
*.zip) unzip "${tarball}" ;;
227+
*.tar.gz | *.tgz) tar -xzf "${tarball}" ;;
228+
*.tar) tar -xf "${tarball}" ;;
229+
*.zip) unzip -u "${tarball}" ;;
227230
*)
228231
log_err "untar unknown archive format for ${tarball}"
229232
return 1
230233
;;
231234
esac
232235
}
236+
mktmpdir() {
237+
test -z "$TMPDIR" && TMPDIR="$(mktemp -d)"
238+
mkdir -p "${TMPDIR}"
239+
echo "${TMPDIR}"
240+
}
233241
http_download_curl() {
234242
local_file=$1
235243
source_url=$2
@@ -332,8 +340,8 @@ EOF
332340
PROJECT_NAME="terraform-provider-bless"
333341
OWNER=chanzuckerberg
334342
REPO="terraform-provider-bless"
335-
BINARY=terraform-provider-bless_{{ .Tag }}
336-
FORMAT=tar.gz
343+
BINARY=terraform-provider-bless
344+
FORMAT=zip
337345
OS=$(uname_os)
338346
ARCH=$(uname_arch)
339347
PREFIX="$OWNER/$REPO"
@@ -350,7 +358,7 @@ uname_arch_check "$ARCH"
350358

351359
parse_args "$@"
352360

353-
get_binaries
361+
check_platform
354362

355363
tag_to_version
356364

@@ -365,7 +373,7 @@ log_info "found version: ${VERSION} for ${TAG}/${OS}/${ARCH}"
365373
NAME=${PROJECT_NAME}_${VERSION}_${OS}_${ARCH}
366374
TARBALL=${NAME}.${FORMAT}
367375
TARBALL_URL=${GITHUB_DOWNLOAD}/${TAG}/${TARBALL}
368-
CHECKSUM=${PROJECT_NAME}_${VERSION}_checksums.txt
376+
CHECKSUM=${PROJECT_NAME}_${VERSION}_SHA256SUMS
369377
CHECKSUM_URL=${GITHUB_DOWNLOAD}/${TAG}/${CHECKSUM}
370378

371379

0 commit comments

Comments
 (0)