Skip to content

Commit

Permalink
Compare using lower case
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLocehiliosan committed Aug 6, 2023
1 parent 91812c9 commit 2fa70b8
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions yadm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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}"
Expand Down

0 comments on commit 2fa70b8

Please sign in to comment.