summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2025-05-07 19:00:13 +0100
committerLeah Rowe <leah@libreboot.org>2025-05-07 19:00:13 +0100
commitcba04aa74b816cbd5f1266a73962f6dd48ee2892 (patch)
tree51e07a1d59a432fa9486ea05878393d43e419eb8
parenta94bd3c0939fac05a902af2cce2cf862ecdf9200 (diff)
init.sh: Use readlink in pybin()
Use realpath only as a fallback. Signed-off-by: Leah Rowe <leah@libreboot.org>
-rw-r--r--include/init.sh3
-rw-r--r--include/lib.sh12
2 files changed, 13 insertions, 2 deletions
diff --git a/include/init.sh b/include/init.sh
index 1be860ea..5032d734 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 950a07c8..99e59a1a 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"