From 9ccfee43e76766f6a2c016cc2a759f932e478518 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Wed, 7 May 2025 19:00:13 +0100 Subject: [PATCH] init.sh: Use readlink in pybin() Use realpath only as a fallback. Signed-off-by: Leah Rowe --- include/init.sh | 3 +-- include/lib.sh | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/init.sh b/include/init.sh index 2ca9fd0..9446835 100644 --- a/include/init.sh +++ b/include/init.sh @@ -80,8 +80,7 @@ pybin() # ideally, don't rely on PATH or hardcoded paths if python venv. # use the *real*, direct executable linked to by the venv symlink if [ $venv -gt 0 ] && [ -L "`command -v "$1" 2>/dev/null`" ]; then - # realpath isn't posix, but available mostly universally - pypath="$(realpath \ + pypath="$(findpath \ "$(command -v "$1" 2>/dev/null)" 2>/dev/null || :)" [ -e "$pypath" ] && [ ! -d "$pypath" ] && \ [ -x "$pypath" ] && printf "%s\n" "$pypath" && return 0; : diff --git a/include/lib.sh b/include/lib.sh index 950a07c..99e59a1 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -144,6 +144,18 @@ singletree() return 1 } +findpath() +{ + [ $# -gt 0 ] || err "findpath: No arguments provided" + while [ $# -gt 0 ]; do + found="`readlink -f "$1" 2>/dev/null`" || return 1; : + [ -n "$found" ] || found="`realpath "$1" 2>/dev/null`" || \ + return 1; : + printf "%s\n" "$found" + shift 1 + done +} + fx_() { fd="`mktemp`" && x_ rm -f "$fd" && x_ touch "$fd"