From d450d5a46342b3c50bccb1b61ff655f509db4538 Mon Sep 17 00:00:00 2001 From: Laurent Cheylus Date: Mon, 1 Jan 2024 22:21:10 +0100 Subject: [PATCH] show-utils.sh: modify script to be compatible with BSD OS - Use /usr/bin/env bash instead of /bin/sh to define OSTYPE - Use GNU realpath on BSD OS (FreeBSD and OpenBSD) Signed-off-by: Laurent Cheylus --- util/show-utils.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/util/show-utils.sh b/util/show-utils.sh index dda01abe2..f53a92cc8 100755 --- a/util/show-utils.sh +++ b/util/show-utils.sh @@ -1,13 +1,23 @@ -#!/bin/sh +#!/usr/bin/env bash -# spell-checker:ignore (utils) cksum coreutils dircolors hashsum mkdir mktemp printenv printf readlink realpath rmdir shuf tsort unexpand +# spell-checker:ignore (shell) OSTYPE +# spell-checker:ignore (utils) cksum coreutils dircolors hashsum mkdir mktemp printenv printf readlink realpath grealpath rmdir shuf tsort unexpand # spell-checker:ignore (jq) deps startswith +# Use GNU version for realpath on *BSD +case "$OSTYPE" in + *bsd*) + REALPATH="grealpath" + ;; + *) + REALPATH="realpath" + ;; +esac + ME="${0}" ME_dir="$(dirname -- "${ME}")" ME_parent_dir="$(dirname -- "${ME_dir}")" -# NOTE: On FreeBSD, `-mP` arguments are not available. -ME_parent_dir_abs="$(realpath -mP -- "${ME_parent_dir}" || realpath -- "${ME_parent_dir}")" +ME_parent_dir_abs="$("${REALPATH}" -mP -- "${ME_parent_dir}" || "${REALPATH}" -- "${ME_parent_dir}")" # refs: ,