tests+samples: Check for --help support to determine stat/sed tools flavor

Using the kernel name was not a good choice for determining which flavor
(BSD vs. GNU) of stat, sed, and install was being used since one could
install either one of them at least on MacOS. Instead, check whether
--help is supported by these tools.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2026-05-19 16:42:27 +00:00 committed by Stefan Berger
parent c43003b954
commit 895df2c36e
4 changed files with 7 additions and 7 deletions

View File

@ -26,7 +26,7 @@ logerr()
# @1: filename
function get_filesize()
{
if [[ "$(uname -s)" =~ (Linux|CYGWIN_NT-) ]]; then
if stat --help &>/dev/null; then
stat -c%s "$1"
else
# OpenBSD

View File

@ -735,7 +735,7 @@ function run_swtpm_bios()
# @1: filename
function get_filesize()
{
if [[ "$(uname -s)" =~ (Linux|CYGWIN_NT-|GNU) ]]; then
if stat --help &>/dev/null; then
stat -c%s "$1"
else
# OpenBSD
@ -748,7 +748,7 @@ function get_filesize()
# @1: filename
function get_filemode()
{
if [[ "$(uname -s)" =~ (Linux|CYGWIN_NT-) ]]; then
if stat --help &>/dev/null; then
stat -c%a "$1"
else
# BSDs
@ -761,7 +761,7 @@ function get_filemode()
# @1: filename
function get_fileowner()
{
if [[ "$(uname -s)" =~ (Linux|CYGWIN_NT-|GNU) ]]; then
if stat --help &>/dev/null; then
stat -c"%u %g" "$1"
else
# BSDs
@ -774,7 +774,7 @@ function get_fileowner()
# @1: filename
function get_fileowner_names()
{
if [[ "$(uname -s)" =~ (Linux|CYGWIN_NT-|GNU) ]]; then
if stat --help &>/dev/null; then
stat -c"%U %G" "$1"
else
# BSDs

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
if [[ "$(uname -s)" =~ (Linux|CYGWIN_NT-) ]]; then
if install --help &>/dev/null; then
install -D "$1" "$2"
else
mkdir -p "$(dirname "$2")"

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
if [[ "$(uname -s)" =~ (Linux|CYGWIN_NT-|GNU) ]]; then
if sed --help &>/dev/null; then
sed -i "$1" "$2"
else
sed -i '' "$1" "$2"