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
1 changed files with 16 additions and 6 deletions

22
yadm
View File

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