Refactory

This commit is contained in:
Shiming Zhang
2021-11-18 19:13:57 +08:00
parent 6867da26c8
commit 6c1dbcdcb3
14 changed files with 300 additions and 321 deletions

45
hack/helper.sh Executable file
View File

@@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
ROOT="${ROOT:-$(dirname "${BASH_SOURCE}")/..}"
DEFAULT_REGEX='^([a-z]+-)?[a-z]*[0-9]+(\.[0-9]+){0,2}(-.+)?$|^[a-z]+$'
SKOPEO="${SKOPEO:-skopeo}"
ROOT=$(realpath ${ROOT})
function helper::replace_domain() {
local domain="${1}"
local file="${2:-domain.txt}"
for line in $(cat ${file}); do
line="${line/ /}"
if [[ "${line}" == "" ]]; then
continue
fi
key="${line%=*}"
val="${line##*=}"
if [[ "${key}" == "" || "${val}" == "" ]]; then
continue
fi
if [[ "${domain}" =~ ^${key} ]]; then
echo "${domain}" | sed -e "s#^${key}#${val}#"
return 0
fi
done
echo "Error: domain ${domain} not found"
return 1
}
function helper::get_source() {
local source="${1:-mirror.txt}"
cat "${source}" | tr -d ' ' | grep -v -E '^$' | grep -v -E '^#'
}
function helper::exclude() {
local exclude="${1:-exclude.txt}"
local tmp=$(cat "${exclude}" | tr -d ' ' | grep -v -E '^$' | grep -v -E '^#' | tr '\n' '|')
echo "${tmp%|}"
}