Update image match

This commit is contained in:
Shiming Zhang
2024-06-27 11:16:19 +08:00
parent cd9efa259c
commit 55e09223e4
4 changed files with 56 additions and 6 deletions

44
hack/fmt-image-match.sh Executable file
View File

@@ -0,0 +1,44 @@
#!/usr/bin/env bash
function check_match() {
local image=$1
local lines=$2
for line in ${lines}; do
if [[ "${line}" == *"**" ]]; then
if [[ "${image}" == "${line%\*\*}"* ]]; then
return
fi
elif [[ "${line}" == *"*" ]]; then
if [[ "${image}" == "${line%\*}"* ]]; then
if [[ "${image#"${line%\*}"}" != *"/"* ]]; then
return
fi
fi
fi
done
echo "${image}"
}
function format() {
local file=$1
local lines="$(cat "${file}")"
for line in ${lines}; do
if [[ "${line}" != *"*" ]]; then
check_match "${line}" "${lines}"
fi
done
for line in ${lines}; do
if [[ "${line}" == *"*" ]]; then
echo ${line}
fi
done
}
export LC_ALL=C
file=$1
format "${file}" |
sort -u |
grep -v '^$' >$1.tmp && mv $1.tmp $1

9
hack/verify-image-match.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/usr/bin/env bash
export LC_ALL=C
cp $1 $1.bak
$(dirname "${BASH_SOURCE}")/fmt-image-match.sh $1.bak
diff -c $1 $1.bak && rm $1.bak