From 09bd6dffd92b0e9735e4885882fa411348b4d01d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lesimple?= Date: Tue, 17 Nov 2020 11:14:34 +0100 Subject: [PATCH] fix: freebsd: add md5sum_compat() to account for systems where md5sum's binary name is gmd5sum --- bin/admin/install | 3 ++- bin/sudogen/generate-sudoers.sh | 2 +- lib/shell/functions.inc | 9 +++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bin/admin/install b/bin/admin/install index 8e1ce20..7e42b9e 100755 --- a/bin/admin/install +++ b/bin/admin/install @@ -436,7 +436,8 @@ if [ "$nothing" = 0 ]; then action_detail "... we would divide by zero! fallback to a non-random random, such as $n" random=$n else - random=$(( ( 0x$(echo "$(hostname -f) $placeholder $file" | md5sum | cut -c1-4) % (m-n) ) + n )) + # shellcheck disable=SC2119 + random=$(( ( 0x$(echo "$(hostname -f) $placeholder $file" | md5sum_compat | cut -c1-4) % (m-n) ) + n )) fi action_detail "... in above file, replacing $placeholder by $random" sed_compat "s/$placeholder/$random/g" "$destfile" diff --git a/bin/sudogen/generate-sudoers.sh b/bin/sudogen/generate-sudoers.sh index 28cf9a9..c9b2569 100755 --- a/bin/sudogen/generate-sudoers.sh +++ b/bin/sudogen/generate-sudoers.sh @@ -32,7 +32,7 @@ generate_account_sudoers() normalized_account=$(sed -re 's/[^A-Z0-9_]/_/gi' <<< "$account") # as we're reducing the amount of possible chars in normalized_account # we could have collisions: use MD5 to generate a uniq suffix - account_suffix=$(md5sum - <<< "$account" | cut -c1-6) + account_suffix=$(md5sum_compat - <<< "$account" | cut -c1-6) normalized_account="${normalized_account}_${account_suffix}" # lowercase is prohibited normalized_account=$(tr '[:lower:]' '[:upper:]' <<< "$normalized_account") diff --git a/lib/shell/functions.inc b/lib/shell/functions.inc index dc392be..c667ae0 100644 --- a/lib/shell/functions.inc +++ b/lib/shell/functions.inc @@ -108,6 +108,15 @@ sed_compat() fi } +md5sum_compat() +{ + if command -v gmd5sum >/dev/null; then + gmd5sum "$@"; return $? + else + md5sum "$@"; return $? + fi +} + useradd_compat() { local _user="$1" _uid="" _home="" _shell="" _gid="" _extra=""