From 355387066850f18be4197cd0cc86a33ab1a52087 Mon Sep 17 00:00:00 2001 From: William Petit Date: Wed, 15 Jun 2022 21:09:18 +0200 Subject: [PATCH] feat(install): fix script execution on alpine fix #1 --- .gitignore | 1 + Makefile | 12 +++++++++++- misc/script/install.sh | 15 +++++++++++---- misc/script/test_install.sh | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 misc/script/test_install.sh diff --git a/.gitignore b/.gitignore index b958009..0b7bb2d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /internal/server/assets/dist/* dist/ /CHANGELOG.md +/tools diff --git a/Makefile b/Makefile index e086f9d..e366eda 100644 --- a/Makefile +++ b/Makefile @@ -15,9 +15,19 @@ help: ## Display this help watch: deps ## Watching updated files - live reload ( set -o allexport && source .env && set +o allexport && go run -mod=readonly github.com/cortesi/modd/cmd/modd@latest ) -test: deps ## Executing tests +.PHONY: help +test: test-go test-install-script ## Executing tests + +test-go: deps ( set -o allexport && source .env && set +o allexport && go test -v -race -count=1 $(GOTEST_ARGS) ./... ) +test-install-script: tools/bin/bash_unit + tools/bin/bash_unit ./misc/script/test_install.sh + +tools/bin/bash_unit: + mkdir -p tools/bin + cd tools/bin && bash <(curl -s https://raw.githubusercontent.com/pgrange/bash_unit/master/install.sh) + lint: ## Lint sources code golangci-lint run --enable-all $(LINT_ARGS) diff --git a/misc/script/install.sh b/misc/script/install.sh index 5509c0f..6d50dc6 100644 --- a/misc/script/install.sh +++ b/misc/script/install.sh @@ -4,6 +4,7 @@ set -e FORMIDABLE_RELEASES_URL="https://github.com/Bornholm/formidable/releases" FORMIDABLE_DESTDIR="." FORMIDABLE_FILE_BASENAME="frmd" +FORMIDABLE_PLATEFORM_SUFFIX="$(uname -s)_$(uname -m)" function main { test -z "${FORMIDABLE_VERSION}" && FORMIDABLE_VERSION="$(curl -sfL -o /dev/null -w %{url_effective} "${FORMIDABLE_RELEASES_URL}/latest" | @@ -18,7 +19,7 @@ function main { } test -z "${FORMIDABLE_TMPDIR}" && FORMIDABLE_TMPDIR="$(mktemp -d)" - export TAR_FILE="${FORMIDABLE_TMPDIR}/${FORMIDABLE_FILE_BASENAME}_${FORMIDABLE_VERSION}_$(uname -s)_$(uname -m).tar.gz" + export TAR_FILE="${FORMIDABLE_TMPDIR}/${FORMIDABLE_FILE_BASENAME}_${FORMIDABLE_VERSION}_${FORMIDABLE_PLATEFORM_SUFFIX}.tar.gz" ( cd "${FORMIDABLE_TMPDIR}" @@ -26,14 +27,14 @@ function main { # Download Formidable echo "Downloading Formidable ${FORMIDABLE_VERSION}..." curl -sfLo "${TAR_FILE}" \ - "${FORMIDABLE_RELEASES_URL}/download/${FORMIDABLE_VERSION}/${FORMIDABLE_FILE_BASENAME}_${FORMIDABLE_VERSION}_$(uname -s)_$(uname -m).tar.gz" || + "${FORMIDABLE_RELEASES_URL}/download/${FORMIDABLE_VERSION}/${FORMIDABLE_FILE_BASENAME}_${FORMIDABLE_VERSION}_${FORMIDABLE_PLATEFORM_SUFFIX}.tar.gz" || ( echo "Error while downloading Formidable !" >&2 && exit 1 ) # Download checksums curl -sfLo "checksums.txt" "${FORMIDABLE_RELEASES_URL}/download/${FORMIDABLE_VERSION}/checksums.txt" - echo "Verifying checksums..." - sha256sum --ignore-missing --quiet --check checksums.txt || + echo "Verifying checksum..." + check_sum || ( echo "Error while verifying checksums !" >&2 && exit 1 ) ) @@ -46,4 +47,10 @@ function main { echo "You can now use '${FORMIDABLE_DESTDIR}/${FORMIDABLE_FILE_BASENAME}', enjoy !" } +function check_sum { + set -o pipefail + cat checksums.txt | grep frmd_*_${FORMIDABLE_PLATEFORM_SUFFIX}.tar.gz | sha256sum -c + set +o pipefail +} + main $@ \ No newline at end of file diff --git a/misc/script/test_install.sh b/misc/script/test_install.sh new file mode 100644 index 0000000..a001d23 --- /dev/null +++ b/misc/script/test_install.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )"; + +function test_install_ubuntu_20.04 { + cat <