From 98d78d45dad32de5be812a6488ecb5268b042e46 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Fri, 25 Aug 2023 23:17:43 +0200 Subject: [PATCH 1/4] Parametrize lib dir in install.sh Co-authored-by: Kai Kang --- bin/bats | 4 +++- install.sh | 12 +++++++---- lib/bats-core/test_functions.bash | 4 ++-- lib/bats-core/tracing.bash | 4 ++-- lib/bats-core/warnings.bash | 2 +- libexec/bats-core/bats | 2 +- libexec/bats-core/bats-exec-file | 10 ++++----- libexec/bats-core/bats-exec-suite | 8 ++++---- libexec/bats-core/bats-exec-test | 8 ++++---- libexec/bats-core/bats-format-junit | 2 +- libexec/bats-core/bats-format-pretty | 2 +- libexec/bats-core/bats-format-tap | 2 +- libexec/bats-core/bats-format-tap13 | 2 +- libexec/bats-core/bats-preprocess | 2 +- shellcheck.sh | 2 +- test/bats.bats | 2 +- test/fixtures/formatter/echo-formatter | 2 +- test/install.bats | 24 +++++++++++----------- test/test_helper.bash | 2 +- uninstall.sh | 28 ++++++++++++++++++++------ 20 files changed, 73 insertions(+), 51 deletions(-) diff --git a/bin/bats b/bin/bats index 5327f7ff8d..97d2248056 100755 --- a/bin/bats +++ b/bin/bats @@ -55,6 +55,8 @@ if ! BATS_PATH=$(bats_readlinkf "${BASH_SOURCE[0]}" 2>/dev/null); then fi export BATS_SAVED_PATH=$PATH +BATS_BASE_LIBDIR=lib # this will be patched with the true value in install.sh + export BATS_ROOT=${BATS_PATH%/*/*} export -f bats_readlinkf -exec env BATS_ROOT="$BATS_ROOT" "$BATS_ROOT/libexec/bats-core/bats" "$@" +exec env BATS_ROOT="$BATS_ROOT" BATS_LIBDIR="${BATS_BASE_LIBDIR:-lib}" "$BATS_ROOT/libexec/bats-core/bats" "$@" diff --git a/install.sh b/install.sh index 39ca662e91..3a85ff627e 100755 --- a/install.sh +++ b/install.sh @@ -3,21 +3,25 @@ set -e BATS_ROOT="${0%/*}" -PREFIX="$1" +PREFIX="${1%/}" LIBDIR="${2:-lib}" if [[ -z "$PREFIX" ]]; then printf '%s\n' \ - "usage: $0 " \ - " e.g. $0 /usr/local" >&2 + "usage: $0 [base_libdir]" \ + " e.g. $0 /usr/local" \ + " $0 /usr/local lib64" >&2 exit 1 fi -install -d -m 755 "$PREFIX"/{bin,libexec/bats-core,"${LIBDIR}"/bats-core,share/man/man{1,7}} +install -d -m 755 "$PREFIX"/{bin,libexec/bats-core,"${LIBDIR}"/bats-core,share/{bats,man/man{1,7}}} + install -m 755 "$BATS_ROOT/bin"/* "$PREFIX/bin" install -m 755 "$BATS_ROOT/libexec/bats-core"/* "$PREFIX/libexec/bats-core" install -m 755 "$BATS_ROOT/lib/bats-core"/* "$PREFIX/${LIBDIR}/bats-core" install -m 644 "$BATS_ROOT/man/bats.1" "$PREFIX/share/man/man1" install -m 644 "$BATS_ROOT/man/bats.7" "$PREFIX/share/man/man7" +sed -i "s#^\(BATS_BASE_LIBDIR=\).*#\1${LIBDIR}#" "$PREFIX/bin/bats" + echo "Installed Bats to $PREFIX/bin/bats" diff --git a/lib/bats-core/test_functions.bash b/lib/bats-core/test_functions.bash index 10ae825915..059d7097d9 100644 --- a/lib/bats-core/test_functions.bash +++ b/lib/bats-core/test_functions.bash @@ -4,7 +4,7 @@ BATS_TEST_DIRNAME="${BATS_TEST_FILENAME%/*}" BATS_TEST_NAMES=() # shellcheck source=lib/bats-core/warnings.bash -source "$BATS_ROOT/lib/bats-core/warnings.bash" +source "$BATS_ROOT/$BATS_LIBDIR/bats-core/warnings.bash" # find_in_bats_lib_path echoes the first recognized load path to # a library in BATS_LIB_PATH or relative to BATS_TEST_DIRNAME. @@ -276,7 +276,7 @@ bats_pipe() { # [-N] [--] command0 [ \| command1 [ \| command2 [...]]] # run commands and return appropriate pipe status local -a __bats_pipe_eval_pipe_status=() - eval "${escaped_args[@]}" '; __bats_pipe_eval_pipe_status=(${PIPESTATUS[@]})' + eval "${escaped_args[*]}" '; __bats_pipe_eval_pipe_status=(${PIPESTATUS[@]})' local result_status= if [ -z "$pipestatus_position" ]; then diff --git a/lib/bats-core/tracing.bash b/lib/bats-core/tracing.bash index 4c16eebc6c..6d46720702 100644 --- a/lib/bats-core/tracing.bash +++ b/lib/bats-core/tracing.bash @@ -1,7 +1,7 @@ #!/usr/bin/env bash # shellcheck source=lib/bats-core/common.bash -source "$BATS_ROOT/lib/bats-core/common.bash" +source "$BATS_ROOT/$BATS_LIBDIR/bats-core/common.bash" bats_capture_stack_trace() { local test_file @@ -336,7 +336,7 @@ bats_setup_tracing() { BATS_ERROR_SUFFIX= BATS_DEBUG_EXCLUDE_PATHS=() # exclude some paths by default - bats_add_debug_exclude_path "$BATS_ROOT/lib/" + bats_add_debug_exclude_path "$BATS_ROOT/$BATS_LIBDIR/" bats_add_debug_exclude_path "$BATS_ROOT/libexec/" exec 4<&1 # used for tracing diff --git a/lib/bats-core/warnings.bash b/lib/bats-core/warnings.bash index fbb5186a46..5762d7430e 100644 --- a/lib/bats-core/warnings.bash +++ b/lib/bats-core/warnings.bash @@ -1,7 +1,7 @@ #!/usr/bin/env bash # shellcheck source=lib/bats-core/tracing.bash -source "$BATS_ROOT/lib/bats-core/tracing.bash" +source "$BATS_ROOT/$BATS_LIBDIR/bats-core/tracing.bash" # generate a warning report for the parent call's call site bats_generate_warning() { # [--no-stacktrace] [...] diff --git a/libexec/bats-core/bats b/libexec/bats-core/bats index 4a90e4f66e..a3c5b1408d 100755 --- a/libexec/bats-core/bats +++ b/libexec/bats-core/bats @@ -486,7 +486,7 @@ if [[ -n "$setup_suite_file" ]]; then fi # shellcheck source=lib/bats-core/validator.bash -source "$BATS_ROOT/lib/bats-core/validator.bash" +source "$BATS_ROOT/$BATS_LIBDIR/bats-core/validator.bash" trap 'BATS_INTERRUPTED=true' INT # let the lower levels handle the interruption diff --git a/libexec/bats-core/bats-exec-file b/libexec/bats-core/bats-exec-file index d6f5b9e381..c25adfce76 100755 --- a/libexec/bats-core/bats-exec-file +++ b/libexec/bats-core/bats-exec-file @@ -62,15 +62,15 @@ export BATS_TEST_FILENAME="$filename" # shellcheck source=lib/bats-core/preprocessing.bash # shellcheck disable=SC2153 -source "$BATS_ROOT/lib/bats-core/preprocessing.bash" +source "$BATS_ROOT/$BATS_LIBDIR/bats-core/preprocessing.bash" bats_run_setup_file() { # shellcheck source=lib/bats-core/tracing.bash # shellcheck disable=SC2153 - source "$BATS_ROOT/lib/bats-core/tracing.bash" + source "$BATS_ROOT/$BATS_LIBDIR/bats-core/tracing.bash" # shellcheck source=lib/bats-core/test_functions.bash # shellcheck disable=SC2153 - source "$BATS_ROOT/lib/bats-core/test_functions.bash" + source "$BATS_ROOT/$BATS_LIBDIR/bats-core/test_functions.bash" exec 3<&1 @@ -125,7 +125,7 @@ bats_file_teardown_trap() { } # shellcheck source=lib/bats-core/common.bash -source "$BATS_ROOT/lib/bats-core/common.bash" +source "$BATS_ROOT/$BATS_LIBDIR/bats-core/common.bash" # shellcheck disable=SC2317 bats_file_exit_trap() { @@ -243,7 +243,7 @@ bats_run_tests_in_parallel() { local status=0 mkdir -p "$output_folder" # shellcheck source=lib/bats-core/semaphore.bash - source "$BATS_ROOT/lib/bats-core/semaphore.bash" + source "$BATS_ROOT/$BATS_LIBDIR/bats-core/semaphore.bash" bats_semaphore_setup # the test_number_in_file is not yet incremented -> one before the next test to run local test_number_in_suite_of_last_finished_test="$BATS_FILE_FIRST_TEST_NUMBER_IN_SUITE" # stores which test was printed last diff --git a/libexec/bats-core/bats-exec-suite b/libexec/bats-core/bats-exec-suite index cf857c32f1..f8d419c573 100755 --- a/libexec/bats-core/bats-exec-suite +++ b/libexec/bats-core/bats-exec-suite @@ -20,7 +20,7 @@ abort() { } # shellcheck source=lib/bats-core/common.bash disable=SC2153 -source "$BATS_ROOT/lib/bats-core/common.bash" +source "$BATS_ROOT/$BATS_LIBDIR/bats-core/common.bash" while [[ "$#" -ne 0 ]]; do case "$1" in @@ -106,7 +106,7 @@ if [[ "$num_jobs" != 1 ]]; then abort "Cannot execute \"${num_jobs}\" jobs without GNU parallel" fi # shellcheck source=lib/bats-core/semaphore.bash - source "${BATS_ROOT}/lib/bats-core/semaphore.bash" + source "${BATS_ROOT}/$BATS_LIBDIR/bats-core/semaphore.bash" bats_semaphore_setup fi @@ -348,7 +348,7 @@ fi IFS=$'\n' read -d '' -r -a BATS_UNIQUE_TEST_FILENAMES < <(printf "%s\n" "$@" | nl | sort -k 2 | uniq -f 1 | sort -n | cut -f 2-) || true # shellcheck source=lib/bats-core/tracing.bash -source "$BATS_ROOT/lib/bats-core/tracing.bash" +source "$BATS_ROOT/$BATS_LIBDIR/bats-core/tracing.bash" bats_setup_tracing trap bats_suite_exit_trap EXIT @@ -425,7 +425,7 @@ if [[ -n "$setup_suite_file" ]]; then # shellcheck disable=SC2034 # will be used in the sourced file below BATS_TEST_FILENAME="$setup_suite_file" # shellcheck source=lib/bats-core/test_functions.bash - source "$BATS_ROOT/lib/bats-core/test_functions.bash" + source "$BATS_ROOT/$BATS_LIBDIR/bats-core/test_functions.bash" # shellcheck disable=SC1090 source "$setup_suite_file" diff --git a/libexec/bats-core/bats-exec-test b/libexec/bats-core/bats-exec-test index dc10a8bf3f..f5d0ba177a 100755 --- a/libexec/bats-core/bats-exec-test +++ b/libexec/bats-core/bats-exec-test @@ -79,9 +79,9 @@ bats_create_test_tmpdirs() { # load the test helper functions like `load` or `run` that are needed to run a (preprocessed) .bats file without bash errors # shellcheck source=lib/bats-core/test_functions.bash disable=SC2153 -source "$BATS_ROOT/lib/bats-core/test_functions.bash" +source "$BATS_ROOT/$BATS_LIBDIR/bats-core/test_functions.bash" # shellcheck source=lib/bats-core/tracing.bash disable=SC2153 -source "$BATS_ROOT/lib/bats-core/tracing.bash" +source "$BATS_ROOT/$BATS_LIBDIR/bats-core/tracing.bash" bats_teardown_trap() { bats_check_status_from_trap @@ -109,7 +109,7 @@ bats_teardown_trap() { } # shellcheck source=lib/bats-core/common.bash -source "$BATS_ROOT/lib/bats-core/common.bash" +source "$BATS_ROOT/$BATS_LIBDIR/bats-core/common.bash" bats_exit_trap() { local status @@ -352,7 +352,7 @@ bats_perform_test() { trap bats_interrupt_trap INT # shellcheck source=lib/bats-core/preprocessing.bash -source "$BATS_ROOT/lib/bats-core/preprocessing.bash" +source "$BATS_ROOT/$BATS_LIBDIR/bats-core/preprocessing.bash" exec 3<&1 diff --git a/libexec/bats-core/bats-format-junit b/libexec/bats-core/bats-format-junit index 5436157e05..9ee1ac3db9 100755 --- a/libexec/bats-core/bats-format-junit +++ b/libexec/bats-core/bats-format-junit @@ -2,7 +2,7 @@ set -euo pipefail # shellcheck source=lib/bats-core/formatter.bash -source "$BATS_ROOT/lib/bats-core/formatter.bash" +source "$BATS_ROOT/$BATS_LIBDIR/bats-core/formatter.bash" BASE_PATH=. diff --git a/libexec/bats-core/bats-format-pretty b/libexec/bats-core/bats-format-pretty index 2b03eed8ea..df09958ab7 100755 --- a/libexec/bats-core/bats-format-pretty +++ b/libexec/bats-core/bats-format-pretty @@ -2,7 +2,7 @@ set -e # shellcheck source=lib/bats-core/formatter.bash -source "$BATS_ROOT/lib/bats-core/formatter.bash" +source "$BATS_ROOT/$BATS_LIBDIR/bats-core/formatter.bash" BASE_PATH=. BATS_ENABLE_TIMING= diff --git a/libexec/bats-core/bats-format-tap b/libexec/bats-core/bats-format-tap index 4aed2c140c..aa1781c58f 100755 --- a/libexec/bats-core/bats-format-tap +++ b/libexec/bats-core/bats-format-tap @@ -3,7 +3,7 @@ set -e trap '' INT # shellcheck source=lib/bats-core/formatter.bash -source "$BATS_ROOT/lib/bats-core/formatter.bash" +source "$BATS_ROOT/$BATS_LIBDIR/bats-core/formatter.bash" bats_tap_stream_plan() { printf "1..%d\n" "$1" diff --git a/libexec/bats-core/bats-format-tap13 b/libexec/bats-core/bats-format-tap13 index 98a3ffafbf..e2047cdf6b 100755 --- a/libexec/bats-core/bats-format-tap13 +++ b/libexec/bats-core/bats-format-tap13 @@ -22,7 +22,7 @@ trap '' INT number_of_printed_log_lines_for_this_test_so_far=0 # shellcheck source=lib/bats-core/formatter.bash -source "$BATS_ROOT/lib/bats-core/formatter.bash" +source "$BATS_ROOT/$BATS_LIBDIR/bats-core/formatter.bash" bats_tap_stream_plan() { printf "TAP version 13\n" diff --git a/libexec/bats-core/bats-preprocess b/libexec/bats-core/bats-preprocess index 5ef831043d..ce45513f32 100755 --- a/libexec/bats-core/bats-preprocess +++ b/libexec/bats-core/bats-preprocess @@ -38,7 +38,7 @@ BATS_VALID_TAG_PATTERN="[-_:[:alnum:]]+" BATS_VALID_TAGS_PATTERN="^ *($BATS_VALID_TAG_PATTERN)?( *, *$BATS_VALID_TAG_PATTERN)* *$" # shellcheck source=lib/bats-core/common.bash -source "$BATS_ROOT/lib/bats-core/common.bash" +source "$BATS_ROOT/$BATS_LIBDIR/bats-core/common.bash" extract_tags() { # local -r tag_type=$1 tags_string=$2 diff --git a/shellcheck.sh b/shellcheck.sh index 3087264452..01f1335a95 100755 --- a/shellcheck.sh +++ b/shellcheck.sh @@ -17,6 +17,6 @@ if [[ $1 == --list ]]; then exit 0 fi -LC_ALL=C.UTF-8 shellcheck "${targets[@]}" +LC_ALL=C.UTF-8 shellcheck -x "${targets[@]}" exit $? diff --git a/test/bats.bats b/test/bats.bats index 011897b026..1e976abe82 100755 --- a/test/bats.bats +++ b/test/bats.bats @@ -565,7 +565,7 @@ END_OF_ERR_MSG @test "test count validator catches mismatch and returns non zero" { # shellcheck source=lib/bats-core/validator.bash - source "$BATS_ROOT/lib/bats-core/validator.bash" + source "$BATS_ROOT/$BATS_LIBDIR/bats-core/validator.bash" export -f bats_test_count_validator reentrant_run bash -c "echo $'1..1\n' | bats_test_count_validator" [[ $status -ne 0 ]] diff --git a/test/fixtures/formatter/echo-formatter b/test/fixtures/formatter/echo-formatter index 87ba817572..df71944610 100755 --- a/test/fixtures/formatter/echo-formatter +++ b/test/fixtures/formatter/echo-formatter @@ -3,7 +3,7 @@ set -e # shellcheck source=lib/bats-core/formatter.bash -source "$BATS_ROOT/lib/bats-core/formatter.bash" +source "$BATS_ROOT/$BATS_LIBDIR/bats-core/formatter.bash" bats_tap_stream_plan() { echo "STREAM_PLAN: $1" diff --git a/test/install.bats b/test/install.bats index 2411bfcb16..a507822580 100644 --- a/test/install.bats +++ b/test/install.bats @@ -17,12 +17,12 @@ setup() { [ "$status" -eq 0 ] [ "$output" == "Installed Bats to $INSTALL_DIR/bin/bats" ] [ -x "$INSTALL_DIR/bin/bats" ] - [ -x "$INSTALL_DIR/lib/bats-core/formatter.bash" ] - [ -x "$INSTALL_DIR/lib/bats-core/preprocessing.bash" ] - [ -x "$INSTALL_DIR/lib/bats-core/semaphore.bash" ] - [ -x "$INSTALL_DIR/lib/bats-core/test_functions.bash" ] - [ -x "$INSTALL_DIR/lib/bats-core/tracing.bash" ] - [ -x "$INSTALL_DIR/lib/bats-core/validator.bash" ] + [ -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/formatter.bash" ] + [ -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/preprocessing.bash" ] + [ -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/semaphore.bash" ] + [ -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/test_functions.bash" ] + [ -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/tracing.bash" ] + [ -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/validator.bash" ] [ -x "$INSTALL_DIR/libexec/bats-core/bats" ] [ -x "$INSTALL_DIR/libexec/bats-core/bats-exec-suite" ] [ -x "$INSTALL_DIR/libexec/bats-core/bats-exec-test" ] @@ -39,12 +39,12 @@ setup() { run "$PATH_TO_UNINSTALL_SHELL" "$INSTALL_DIR" [ "$status" -eq 0 ] [ ! -x "$INSTALL_DIR/bin/bats" ] - [ ! -x "$INSTALL_DIR/lib/bats-core/formatter.bash" ] - [ ! -x "$INSTALL_DIR/lib/bats-core/preprocessing.bash" ] - [ ! -x "$INSTALL_DIR/lib/bats-core/semaphore.bash" ] - [ ! -x "$INSTALL_DIR/lib/bats-core/test_functions.bash" ] - [ ! -x "$INSTALL_DIR/lib/bats-core/tracing.bash" ] - [ ! -x "$INSTALL_DIR/lib/bats-core/validator.bash" ] + [ ! -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/formatter.bash" ] + [ ! -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/preprocessing.bash" ] + [ ! -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/semaphore.bash" ] + [ ! -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/test_functions.bash" ] + [ ! -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/tracing.bash" ] + [ ! -x "$INSTALL_DIR/$BATS_LIBDIR/bats-core/validator.bash" ] [ ! -x "$INSTALL_DIR/libexec/bats-core/bats" ] [ ! -x "$INSTALL_DIR/libexec/bats-core/bats-exec-suite" ] [ ! -x "$INSTALL_DIR/libexec/bats-core/bats-exec-test" ] diff --git a/test/test_helper.bash b/test/test_helper.bash index fa0323bf71..4c52c6c5eb 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -45,7 +45,7 @@ execute_with_unset_bats_vars() { # "$@" } -REENTRANT_RUN_PRESERVE+=(BATS_SAVED_PATH BATS_ROOT BATS_TEST_TAGS BATS_PARALLEL_BINARY_NAME) +REENTRANT_RUN_PRESERVE+=(BATS_SAVED_PATH BATS_ROOT BATS_TEST_TAGS BATS_PARALLEL_BINARY_NAME BATS_LIBDIR) # call run with all BATS_* variables purged from the environment reentrant_run() { # diff --git a/uninstall.sh b/uninstall.sh index ee88e20317..37859536aa 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -3,37 +3,53 @@ set -e BATS_ROOT="${0%/*}" -PREFIX="$1" -LIBDIR="${2:-lib}" +PREFIX="${1%/}" +LIBDIR="${2}" if [[ -z "$PREFIX" ]]; then printf '%s\n' \ - "usage: $0 " \ - " e.g. $0 /usr/local" >&2 + "usage: $0 [base_libdir]" \ + " e.g. $0 /usr/local" \ + " $0 /usr/local lib64" >&2 exit 1 fi +if [[ ! -d "$PREFIX" ]]; then + printf "No valid installation in directory %s.\n" "$PREFIX" + exit 2 +fi + +LIBDIR=$(grep -e '^BATS_BASE_LIBDIR=' "$PREFIX/bin/bats") +eval "$LIBDIR" +LIBDIR="${BATS_BASE_LIBDIR:-lib}" + d="$PREFIX/bin" for elt in "$BATS_ROOT/bin"/*; do elt=${elt##*/} + echo "Removing $d/$elt" rm -f "$d/$elt" done d="$PREFIX/libexec/bats-core" for elt in "$BATS_ROOT/libexec/bats-core"/*; do elt=${elt##*/} + echo "Removing $d/$elt" rm -f "$d/$elt" done -[[ -d "$d" ]] && rmdir "$d" +[[ -d "$d" ]] && echo "Removing $d" && rmdir "$d" d="$PREFIX/${LIBDIR}/bats-core" for elt in "$BATS_ROOT/lib/bats-core"/*; do elt=${elt##*/} + echo "Removing $d/$elt" rm -f "$d/$elt" done -[[ -d "$d" ]] && rmdir "$d" +[[ -d "$d" ]] && echo "Removing $d" && rmdir "$d" +echo "Removing $PREFIX"/share/man/man1/bats.1" rm -f "$PREFIX"/share/man/man1/bats.1 + +echo "Removing $PREFIX"/share/man/man1/bats.7" rm -f "$PREFIX"/share/man/man7/bats.7 echo "Uninstalled Bats from $PREFIX/bin/bats" From a401cd8d4c5e69352fac27b454707debf4dd11f1 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Fri, 25 Aug 2023 23:21:55 +0200 Subject: [PATCH 2/4] Add changelog entry for #487 --- docs/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1323c179b1..8e00b88662 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -19,6 +19,8 @@ The format is based on [Keep a Changelog][kac] and this project adheres to ### Fixed +* `install.sh` now works for deviating `lib/` dirs (like `lib32`,`lib64`) (#487) + #### Documentation * clarify docker usage (#741) From 08d1521752a79a705a363a72b282d5e3f21d1faf Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Fri, 25 Aug 2023 23:56:29 +0200 Subject: [PATCH 3/4] Make uninstall.sh not fail when nothing is installed --- uninstall.sh | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/uninstall.sh b/uninstall.sh index 37859536aa..316097892c 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -4,7 +4,6 @@ set -e BATS_ROOT="${0%/*}" PREFIX="${1%/}" -LIBDIR="${2}" if [[ -z "$PREFIX" ]]; then printf '%s\n' \ @@ -19,37 +18,46 @@ if [[ ! -d "$PREFIX" ]]; then exit 2 fi -LIBDIR=$(grep -e '^BATS_BASE_LIBDIR=' "$PREFIX/bin/bats") -eval "$LIBDIR" +if [ -e "$PREFIX/bin/bats" ]; then + LIBDIR=$(grep -e '^BATS_BASE_LIBDIR=' "$PREFIX/bin/bats") + eval "$LIBDIR" +fi LIBDIR="${BATS_BASE_LIBDIR:-lib}" +remove_file() { # + echo "Removing $1" + rm -f "$1" +} + +remove_directory() { # + local directory=$1 + if [[ -d "$directory" ]]; then + echo "Removing $directory" + rmdir "$directory" + fi +} + d="$PREFIX/bin" for elt in "$BATS_ROOT/bin"/*; do elt=${elt##*/} - echo "Removing $d/$elt" - rm -f "$d/$elt" + remove_file "$d/$elt" done d="$PREFIX/libexec/bats-core" for elt in "$BATS_ROOT/libexec/bats-core"/*; do elt=${elt##*/} - echo "Removing $d/$elt" - rm -f "$d/$elt" + remove_file "$d/$elt" done -[[ -d "$d" ]] && echo "Removing $d" && rmdir "$d" +remove_directory "$d" d="$PREFIX/${LIBDIR}/bats-core" for elt in "$BATS_ROOT/lib/bats-core"/*; do elt=${elt##*/} - echo "Removing $d/$elt" - rm -f "$d/$elt" + remove_file "$d/$elt" done -[[ -d "$d" ]] && echo "Removing $d" && rmdir "$d" - -echo "Removing $PREFIX"/share/man/man1/bats.1" -rm -f "$PREFIX"/share/man/man1/bats.1 +remove_directory "$d" -echo "Removing $PREFIX"/share/man/man1/bats.7" -rm -f "$PREFIX"/share/man/man7/bats.7 +remove_file "$PREFIX"/share/man/man1/bats.1 +remove_file "$PREFIX"/share/man/man7/bats.7 echo "Uninstalled Bats from $PREFIX/bin/bats" From de133ec581fd647650eb146422d76f43c12306b2 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sat, 26 Aug 2023 13:47:34 +0200 Subject: [PATCH 4/4] Avoid platform differences by not using sed --- install.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 3a85ff627e..47f5d34319 100755 --- a/install.sh +++ b/install.sh @@ -22,6 +22,8 @@ install -m 755 "$BATS_ROOT/lib/bats-core"/* "$PREFIX/${LIBDIR}/bats-core" install -m 644 "$BATS_ROOT/man/bats.1" "$PREFIX/share/man/man1" install -m 644 "$BATS_ROOT/man/bats.7" "$PREFIX/share/man/man7" -sed -i "s#^\(BATS_BASE_LIBDIR=\).*#\1${LIBDIR}#" "$PREFIX/bin/bats" +read -rd '' BATS_EXE_CONTENTS <"$PREFIX/bin/bats" || true +BATS_EXE_CONTENTS=${BATS_EXE_CONTENTS/"BATS_BASE_LIBDIR=lib"/"BATS_BASE_LIBDIR=${LIBDIR}"} +printf "%s" "$BATS_EXE_CONTENTS" > "$PREFIX/bin/bats" echo "Installed Bats to $PREFIX/bin/bats"