public-image-mirror/hack/fmt-image-match.sh

45 lines
944 B
Bash
Executable File

#!/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