diff --git a/scripts/check-image.sh b/scripts/check-image.sh index 33c1b53..a002e1a 100755 --- a/scripts/check-image.sh +++ b/scripts/check-image.sh @@ -39,6 +39,7 @@ for line in $(cat not_sync.yaml | yq -j '.not_sync[] | .image_pattern , "=", (.t done LOGFILE="./check-image.log" +echo >"${LOGFILE}" for line in $(cat ./mirror.txt); do line="${line/ /}" @@ -57,13 +58,13 @@ for line in $(cat ./mirror.txt); do domain="${line%%/*}" new_image=$(echo "${line}" | sed "s/^${domain}/${DOMAIN_MAP["${domain}"]}/g") echo "Diff image ${line} ${new_image}" - DEBUG=true INCREMENTAL=true EXCLUDED="${exclude}" ./scripts/diff-image.sh "${line}" "${new_image}" | tee -a "${LOGFILE}" || { + DEBUG=true INCREMENTAL=true EXCLUDED="${exclude}" ./scripts/diff-image.sh "${line}" "${new_image}" 2>&1 | tee -a "${LOGFILE}" || { echo "Error: diff image ${line} ${new_image}" } done -sync=$(cat "${LOGFILE}" | grep " SYNC: " | wc -l | tr -d ' ') -nosync=$(cat "${LOGFILE}" | grep " NOSYNC: " | wc -l | tr -d ' ') +sync="$(cat "${LOGFILE}" | grep " SYNC: " | wc -l | tr -d ' ' || :)" +nosync="$(cat "${LOGFILE}" | grep " NOSYNC: " | wc -l | tr -d ' ' || :)" sum=$(($sync + $nosync)) echo https://img.shields.io/badge/Sync-${sync}%2F${sum}-blue diff --git a/scripts/diff-image.sh b/scripts/diff-image.sh index 3aec503..ab85852 100755 --- a/scripts/diff-image.sh +++ b/scripts/diff-image.sh @@ -100,7 +100,7 @@ function list-tags() { local raw="$(skopeo list-tags --tls-verify=false "docker://${image}" | jq -r '.Tags[]' | sort)" if [[ "${EXCLUDED}" != "" ]]; then - raw="$(echo "${raw}" | grep -v -E "${EXCLUDED}")" + raw="$(echo "${raw}" | grep -v -E "${EXCLUDED}" || :)" fi echo "${raw}" } @@ -134,11 +134,11 @@ function diff-image() { local tags1="$(list-tags ${image1})" local tags2="$(list-tags ${image2})" - local diff_raw="$(diff --unified <(echo "${tags1}") <(echo "${tags2}") | grep -v -E '^---' | grep -v -E '^\+\+\+')" - local diff_data="$(echo "${diff_raw}" | grep -v -E '^ ')" + local diff_raw="$(diff --unified <(echo "${tags1}") <(echo "${tags2}") | grep -v -E '^---' | grep -v -E '^\+\+\+' || :)" + local diff_data="$(echo "${diff_raw}" | grep -v -E '^ ' || :)" if [[ "${INCREMENTAL}" == "true" ]]; then - diff_data="$(echo "${diff_data}" | grep -v -E '^\+')" + diff_data="$(echo "${diff_data}" | grep -v -E '^\+' || :)" fi if [[ "${diff_data}" != "" ]]; then @@ -151,15 +151,15 @@ function diff-image() { echo "DEBUG: diff:" >&2 echo "${diff_data}" >&2 fi - for tag in $(echo "$(echo "${diff_raw}" | grep -E '^-')"); do + for tag in $(echo "${diff_raw}" | grep -E '^-' || :); do tag="${tag#-}" echo "${SELF}: UNSYNC: ${image1}:${tag} and ${image2}:${tag} are not in synchronized, ${image2}:${tag} is empty" >&2 done - for tag in $(echo "$(echo "${diff_raw}" | grep -E '^\+')"); do + for tag in $(echo "${diff_raw}" | grep -E '^\+' || :); do tag="${tag#+}" echo "${SELF}: UNSYNC: ${image1}:${tag} and ${image2}:${tag} are not in synchronized, ${image1}:${tag} is empty" >&2 done - echo "$(echo "${diff_raw}" | grep -E '^ ' | tr -d ' ')" + echo "$(echo "${diff_raw}" | grep -E '^ ' | tr -d ' ' || :)" return 1 fi echo "${SELF}: SYNC-TAGS: ${image1} and ${image2} are in synchronized" >&2