From 620f3af69116c10f5b55f161ad61afdc05ea7cdf Mon Sep 17 00:00:00 2001 From: eval Nya <11857526-nexplorer-3e@users.noreply.gitlab.com> Date: Sun, 18 Jun 2023 12:52:30 +0800 Subject: [PATCH] envkernel.sh: use realpath to deal with symlink Suggest to change suffix to bash: POSIX does not provide a way to detect sourced script path, and the working method in this script is bash-specific. (The sh-method would not working in some cases like shell in shell) Reviewed-by: Oliver Smith Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230618045230.28622-1-11857526-nexplorer-3e@users.noreply.gitlab.com%3E --- helpers/envkernel.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/helpers/envkernel.sh b/helpers/envkernel.sh index c53351bb..5b3ade3a 100644 --- a/helpers/envkernel.sh +++ b/helpers/envkernel.sh @@ -49,7 +49,7 @@ export_pmbootstrap_dir() { # See also: # shellcheck disable=SC3054 if [ -n "${BASH_SOURCE[0]}" ]; then - script_dir="$(dirname "${BASH_SOURCE[0]}")" + script_dir="$(dirname "$(realpath "$BASH_SOURCE")")" else script_dir="$(dirname "$1")" fi @@ -324,9 +324,7 @@ check_and_deactivate() { print_usage() { # shellcheck disable=SC3054 if [ -n "${BASH_SOURCE[0]}" ]; then - echo "usage: source $(basename "${BASH_SOURCE[0]}")" - else - echo "usage: source $(basename "$1")" + echo "usage: source $(basename "$(realpath "$BASH_SOURCE")")" fi echo "optional arguments:" echo " --fish Print fish alias syntax (internally used)"