From fc318b68fc9331ccf51a405ab0bba7563f0c5a67 Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Fri, 11 Oct 2024 17:20:24 +0200 Subject: [PATCH] refactor: format install.sh --- CHANGELOG.md | 2 +- install.sh | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93568f11..146fbc1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ - `DEFAULT_PATH="tests"` - `LOG_PATH="out.log"` - `LOAD_FILE="tests/bootstrap.sh"` -- Add check that git is installed to `install.sh` +- Add check that git is installed to `install.sh` ## [0.17.0](https://github.com/TypedDevs/bashunit/compare/0.16.0...0.17.0) - 2024-10-01 diff --git a/install.sh b/install.sh index 4036360b..865b9f89 100755 --- a/install.sh +++ b/install.sh @@ -1,8 +1,7 @@ #!/bin/bash - +# shellcheck disable=SC2155 # shellcheck disable=SC2164 # shellcheck disable=SC2103 -declare -r BASHUNIT_GIT_REPO="https://github.com/TypedDevs/bashunit" function check_git_is_installed() { if ! command -v git >/dev/null 2>&1; then @@ -11,8 +10,6 @@ function check_git_is_installed() { fi } -check_git_is_installed - function get_latest_tag() { git ls-remote --tags "$BASHUNIT_GIT_REPO" | awk '{print $2}' | @@ -21,14 +18,6 @@ function get_latest_tag() { head -n 1 } -# shellcheck disable=SC2155 -declare -r LATEST_BASHUNIT_VERSION="$(get_latest_tag)" - -DIR=${1-lib} -VERSION=${2-latest} -TAG="$LATEST_BASHUNIT_VERSION" - - function build_and_install_beta() { echo "> Downloading non-stable version: 'beta'" git clone --depth 1 --no-tags https://github.com/TypedDevs/bashunit temp_bashunit 2>/dev/null @@ -64,6 +53,19 @@ function install() { chmod u+x "bashunit" } +######################### +######### MAIN ########## +######################### + +check_git_is_installed + +DIR=${1-lib} +VERSION=${2-latest} + +BASHUNIT_GIT_REPO="https://github.com/TypedDevs/bashunit" +LATEST_BASHUNIT_VERSION="$(get_latest_tag)" +TAG="$LATEST_BASHUNIT_VERSION" + cd "$(dirname "$0")" rm -f "$DIR"/bashunit [ -d "$DIR" ] || mkdir "$DIR"