1
0
Fork 0
mirror of synced 2024-12-04 14:45:36 -05:00

Compare using lower case

This commit is contained in:
Tim Byrne 2023-08-06 13:29:30 -05:00
parent 91812c9742
commit 2fa70b89fe
No known key found for this signature in database
GPG key ID: 14DB4FC2465A4B12

22
yadm
View file

@ -190,28 +190,28 @@ function score_file() {
score=$((score + 0))
# variable conditions
elif [[ "$label" =~ ^(a|arch)$ ]]; then
if [ "$value" = "$local_arch" ]; then
if nocase_cmp "$value" "$local_arch"; then
score=$((score + 1))
else
score=0
return
fi
elif [[ "$label" =~ ^(o|os)$ ]]; then
if [ "$value" = "$local_system" ]; then
if nocase_cmp "$value" "$local_system"; then
score=$((score + 2))
else
score=0
return
fi
elif [[ "$label" =~ ^(d|distro)$ ]]; then
if [ "${value/\ /_}" = "${local_distro/\ /_}" ]; then
if nocase_cmp "${value/\ /_}" "${local_distro/\ /_}"; then
score=$((score + 4))
else
score=0
return
fi
elif [[ "$label" =~ ^(f|distro_family)$ ]]; then
if [ "${value/\ /_}" = "${local_distro_family/\ /_}" ]; then
if nocase_cmp "${value/\ /_}" "${local_distro_family/\ /_}"; then
score=$((score + 8))
else
score=0
@ -225,14 +225,14 @@ function score_file() {
return
fi
elif [[ "$label" =~ ^(h|hostname)$ ]]; then
if [ "$value" = "$local_host" ]; then
if nocase_cmp "$value" "$local_host"; then
score=$((score + 32))
else
score=0
return
fi
elif [[ "$label" =~ ^(u|user)$ ]]; then
if [ "$value" = "$local_user" ]; then
if nocase_cmp "$value" "$local_user"; then
score=$((score + 64))
else
score=0
@ -2131,6 +2131,16 @@ function mk_tmp_dir {
echo "$tempdir"
}
if ((BASH_VERSINFO[0]>3)); then
function nocase_cmp {
[ "${1,,}" = "${2,,}" ]
}
else
function nocase_cmp {
[ "$(to_lower "$1")" = "$(to_lower "$2")" ]
}
fi
function to_lower {
local str="$1"
local length="${#str}"