From 5e028dcc8af25011d2d096da9d5b351c9ce71d72 Mon Sep 17 00:00:00 2001 From: Ryan King Date: Fri, 17 Jul 2020 13:06:45 -0700 Subject: [PATCH 1/2] 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 https://github.com/chanzuckerberg/terraform-provider-bless/pull/34. --- Makefile | 7 ++++++- download.sh | 60 ++++++++++++++++++++++++++++++----------------------- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 045c6996..198591bd 100644 --- a/Makefile +++ b/Makefile @@ -73,4 +73,9 @@ release-prerelease: check-release-prereqs build ## release to github as a 'pre-r git push git push --tags goreleaser release -f .goreleaser.prerelease.yml --debug --rm-dist -.PHONY: release-prerelease \ No newline at end of file +.PHONY: release-prerelease + +install-tf: build ## installs plugin where terraform can find it + mkdir -p $(HOME)/.terraform.d/plugins + cp ./$(BASE_BINARY_NAME) $(HOME)/.terraform.d/plugins/$(BASE_BINARY_NAME) +.PHONY: install-tf diff --git a/download.sh b/download.sh index 237372aa..9e4d3ad4 100644 --- a/download.sh +++ b/download.sh @@ -1,6 +1,6 @@ #!/bin/sh set -e -# Code generated by godownloader on 2019-12-05T18:58:14Z. DO NOT EDIT. +# Code generated by godownloader on 2019-02-06T21:15:11Z. DO NOT EDIT. # usage() { @@ -27,12 +27,11 @@ parse_args() { # over-ridden by flag below BINDIR=${BINDIR:-./bin} - while getopts "b:dh?x" arg; do + while getopts "b:dh?" arg; do case "$arg" in b) BINDIR="$OPTARG" ;; d) log_set_priority 10 ;; h | \?) usage "$0" ;; - x) set -x ;; esac done shift $((OPTIND - 1)) @@ -43,33 +42,39 @@ parse_args() { # network, either nothing will happen or will syntax error # out preventing half-done work execute() { - tmpdir=$(mktemp -d) + tmpdir=$(mktmpdir) log_debug "downloading files into ${tmpdir}" http_download "${tmpdir}/${TARBALL}" "${TARBALL_URL}" http_download "${tmpdir}/${CHECKSUM}" "${CHECKSUM_URL}" hash_sha256_verify "${tmpdir}/${TARBALL}" "${tmpdir}/${CHECKSUM}" srcdir="${tmpdir}" (cd "${tmpdir}" && untar "${TARBALL}") - test ! -d "${BINDIR}" && install -d "${BINDIR}" - for binexe in $BINARIES; do + install -d "${BINDIR}" + for binexe in "terraform-provider-bless_${TAG}" ; do if [ "$OS" = "windows" ]; then binexe="${binexe}.exe" fi install "${srcdir}/${binexe}" "${BINDIR}/" log_info "installed ${BINDIR}/${binexe}" done - rm -rf "${tmpdir}" } -get_binaries() { - case "$PLATFORM" in - darwin/amd64) BINARIES="terraform-provider-bless_{{ .Tag }}" ;; - linux/amd64) BINARIES="terraform-provider-bless_{{ .Tag }}" ;; - windows/amd64) BINARIES="terraform-provider-bless_{{ .Tag }}" ;; - *) - 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" - exit 1 - ;; +is_supported_platform() { + platform=$1 + found=1 + case "$platform" in + darwin/amd64) found=0 ;; + linux/amd64) found=0 ;; esac + return $found +} +check_platform() { + if is_supported_platform "$PLATFORM"; then + # optional logging goes here + true + else + 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" + exit 1 + fi } tag_to_version() { if [ -z "${TAG}" ]; then @@ -87,7 +92,7 @@ tag_to_version() { VERSION=${TAG#v} } adjust_format() { - # change format (tar.gz or zip) based on OS + # change format (tar.gz or zip) based on ARCH true } adjust_os() { @@ -159,9 +164,7 @@ log_crit() { uname_os() { os=$(uname -s | tr '[:upper:]' '[:lower:]') case "$os" in - cygwin_nt*) os="windows" ;; - mingw*) os="windows" ;; - msys_nt*) os="windows" ;; + msys_nt) os="windows" ;; esac echo "$os" } @@ -221,8 +224,8 @@ uname_arch_check() { untar() { tarball=$1 case "${tarball}" in - *.tar.gz | *.tgz) tar --no-same-owner -xzf "${tarball}" ;; - *.tar) tar --no-same-owner -xf "${tarball}" ;; + *.tar.gz | *.tgz) tar -xzf "${tarball}" ;; + *.tar) tar -xf "${tarball}" ;; *.zip) unzip "${tarball}" ;; *) log_err "untar unknown archive format for ${tarball}" @@ -230,6 +233,11 @@ untar() { ;; esac } +mktmpdir() { + test -z "$TMPDIR" && TMPDIR="$(mktemp -d)" + mkdir -p "${TMPDIR}" + echo "${TMPDIR}" +} http_download_curl() { local_file=$1 source_url=$2 @@ -332,8 +340,8 @@ EOF PROJECT_NAME="terraform-provider-bless" OWNER=chanzuckerberg REPO="terraform-provider-bless" -BINARY=terraform-provider-bless_{{ .Tag }} -FORMAT=tar.gz +BINARY=terraform-provider-bless +FORMAT=zip OS=$(uname_os) ARCH=$(uname_arch) PREFIX="$OWNER/$REPO" @@ -350,7 +358,7 @@ uname_arch_check "$ARCH" parse_args "$@" -get_binaries +check_platform tag_to_version @@ -365,7 +373,7 @@ log_info "found version: ${VERSION} for ${TAG}/${OS}/${ARCH}" NAME=${PROJECT_NAME}_${VERSION}_${OS}_${ARCH} TARBALL=${NAME}.${FORMAT} TARBALL_URL=${GITHUB_DOWNLOAD}/${TAG}/${TARBALL} -CHECKSUM=${PROJECT_NAME}_${VERSION}_checksums.txt +CHECKSUM=${PROJECT_NAME}_${VERSION}_SHA256SUMS CHECKSUM_URL=${GITHUB_DOWNLOAD}/${TAG}/${CHECKSUM} From 46adda9cc7345e78d3ab259c8b09d91c31fe3f63 Mon Sep 17 00:00:00 2001 From: Ryan King Date: Fri, 17 Jul 2020 13:28:15 -0700 Subject: [PATCH 2/2] unzip -u --- download.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/download.sh b/download.sh index 9e4d3ad4..4059c4a4 100644 --- a/download.sh +++ b/download.sh @@ -226,7 +226,7 @@ untar() { case "${tarball}" in *.tar.gz | *.tgz) tar -xzf "${tarball}" ;; *.tar) tar -xf "${tarball}" ;; - *.zip) unzip "${tarball}" ;; + *.zip) unzip -u "${tarball}" ;; *) log_err "untar unknown archive format for ${tarball}" return 1