-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathdiff.sh
executable file
·76 lines (61 loc) · 1.89 KB
/
diff.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
source "$(dirname "${BASH_SOURCE}")/helper.sh"
cd "${ROOT}"
DEBUG="${DEBUG:-}"
INCREMENTAL="${INCREMENTAL:-}"
QUICKLY="${QUICKLY:-}"
SYNC="${SYNC:-}"
PARALLET="${PARALLET:-0}"
PARALLET_JOBS="${PARALLET_JOBS:-4}"
EXCLUDE="$(helper::exclude)"
declare -A DOMAIN_MAP=()
function wait_jobs() {
local job_num=${1:-3}
local perc=$(jobs -p | wc -l)
while [ "${perc}" -gt "${job_num}" ]; do
sleep 1
perc=$(jobs -p | wc -l)
done
}
function sync_with_domain() {
local domain="${1}"
local list=$(echo ${DOMAIN_MAP[${domain}]} | tr ' ' '\n' | shuf)
for image in ${list}; do
regex="${DEFAULT_REGEX}"
if [[ "${image#*/}" =~ ":" ]]; then
regex="${image##*:}"
image="${image%:*}"
fi
local to="$(helper::replace_domain "${domain}/${image}")"
local logfile="${to//\//_}_sync.log"
echo >"${logfile}"
DEBUG="${DEBUG}" SYNC="${SYNC}" QUICKLY="${QUICKLY}" INCREMENTAL="${INCREMENTAL}" PARALLET="${PARALLET}" FOCUS="${regex}" SKIP="${EXCLUDE}" ./hack/diff-image.sh "${domain}/${image}" "${to}" 2>&1 | tee -a "${logfile}" || {
echo "Error: diff image ${domain}/${image} $(helper::replace_domain "${domain}/${image}")"
}
done
}
function main() {
for image in $(helper::get_source); do
key="${image%%/*}"
val="${image#*/}"
if [[ -v "DOMAIN_MAP[${key}]" ]]; then
DOMAIN_MAP["${key}"]+=" ${val}"
else
DOMAIN_MAP["${key}"]="${val}"
fi
done
for domain in "${!DOMAIN_MAP[@]}"; do
if [[ "${PARALLET_JOBS}" -eq 0 ]]; then
sync_with_domain "${domain}"
else
wait_jobs "${PARALLET_JOBS}"
sync_with_domain "${domain}" &
fi
done
wait
}
trap "trap - SIGTERM && kill 0 && echo exit..." SIGTERM SIGINT
main