mirror of
https://github.com/ovh/the-bastion.git
synced 2025-09-12 07:54:36 +08:00
fix: freebsd: add md5sum_compat()
to account for systems where md5sum's binary name is gmd5sum
This commit is contained in:
parent
4105c10193
commit
09bd6dffd9
3 changed files with 12 additions and 2 deletions
|
@ -436,7 +436,8 @@ if [ "$nothing" = 0 ]; then
|
||||||
action_detail "... we would divide by zero! fallback to a non-random random, such as $n"
|
action_detail "... we would divide by zero! fallback to a non-random random, such as $n"
|
||||||
random=$n
|
random=$n
|
||||||
else
|
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
|
fi
|
||||||
action_detail "... in above file, replacing $placeholder by $random"
|
action_detail "... in above file, replacing $placeholder by $random"
|
||||||
sed_compat "s/$placeholder/$random/g" "$destfile"
|
sed_compat "s/$placeholder/$random/g" "$destfile"
|
||||||
|
|
|
@ -32,7 +32,7 @@ generate_account_sudoers()
|
||||||
normalized_account=$(sed -re 's/[^A-Z0-9_]/_/gi' <<< "$account")
|
normalized_account=$(sed -re 's/[^A-Z0-9_]/_/gi' <<< "$account")
|
||||||
# as we're reducing the amount of possible chars in normalized_account
|
# as we're reducing the amount of possible chars in normalized_account
|
||||||
# we could have collisions: use MD5 to generate a uniq suffix
|
# 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}"
|
normalized_account="${normalized_account}_${account_suffix}"
|
||||||
# lowercase is prohibited
|
# lowercase is prohibited
|
||||||
normalized_account=$(tr '[:lower:]' '[:upper:]' <<< "$normalized_account")
|
normalized_account=$(tr '[:lower:]' '[:upper:]' <<< "$normalized_account")
|
||||||
|
|
|
@ -108,6 +108,15 @@ sed_compat()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
md5sum_compat()
|
||||||
|
{
|
||||||
|
if command -v gmd5sum >/dev/null; then
|
||||||
|
gmd5sum "$@"; return $?
|
||||||
|
else
|
||||||
|
md5sum "$@"; return $?
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
useradd_compat()
|
useradd_compat()
|
||||||
{
|
{
|
||||||
local _user="$1" _uid="" _home="" _shell="" _gid="" _extra=""
|
local _user="$1" _uid="" _home="" _shell="" _gid="" _extra=""
|
||||||
|
|
Loading…
Add table
Reference in a new issue