Skip to content
Permalink
Browse files

Fix issues flagged by shellcheck

  • Loading branch information...
philip-linaro committed Sep 24, 2019
1 parent 4fa3d78 commit 0a8e336cef8cb36c5388db85a5e60d25ec82b823
Showing with 12 additions and 5 deletions.
  1. +12 −5 check-links.sh
@@ -9,17 +9,18 @@ function get_tag_for_latest(){
REPOSITORY="linaroits/linkcheck"
TARGET_TAG="latest"
# check that we have Internet access - bail quickly if we don't
HEAD=$(curl -s "https://auth.docker.io") || return $?
_=$(curl -s "https://auth.docker.io") || return $?
# get authorization token
TOKEN=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$REPOSITORY:pull" | jq -r .token) || return $?
# find all tags
ALL_TAGS=$(curl -s -H "Authorization: Bearer $TOKEN" https://index.docker.io/v2/$REPOSITORY/tags/list | jq -r .tags[]) || return $?
# get image digest for target
TARGET_DIGEST=$(curl -s -D - -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.docker.distribution.manifest.v2+json" https://index.docker.io/v2/$REPOSITORY/manifests/$TARGET_TAG | grep Docker-Content-Digest | cut -d ' ' -f 2) || return $?
# for each tags
# Iterate through the tags, but we need to use unquoted bash expansion so turn off the shellcheck warning
# shellcheck disable=SC2068
for tag in ${ALL_TAGS[@]}; do
# get image digest
digest=$(curl -s -D - -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.docker.distribution.manifest.v2+json" https://index.docker.io/v2/$REPOSITORY/manifests/$tag | grep Docker-Content-Digest | cut -d ' ' -f 2) || return $?
digest=$(curl -s -D - -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.docker.distribution.manifest.v2+json" "https://index.docker.io/v2/$REPOSITORY/manifests/$tag" | grep Docker-Content-Digest | cut -d ' ' -f 2) || return $?
# check digest
if [ "$TARGET_DIGEST" = "$digest" ] && [ "$tag" != "$TARGET_TAG" ]; then
LATEST_ALIAS="$tag"
@@ -29,17 +30,23 @@ function get_tag_for_latest(){

#
# If possible, show which container version this is
if [ ! -z "${BAMBOO_BUILD}" ]; then
if [ -n "${BAMBOO_BUILD}" ]; then
echo "Container built by bamboo.linaro.org: ${BAMBOO_BUILD}"
get_tag_for_latest || LATEST_ALIAS=""
if [ ! -z "$LATEST_ALIAS" ] && [ "$LATEST_ALIAS" != "${BAMBOO_BUILD}" ]; then
if [ -n "$LATEST_ALIAS" ] && [ "$LATEST_ALIAS" != "${BAMBOO_BUILD}" ]; then
echo "************************************************************"
echo "WARNING! This does not appear to be the latest Docker image:"
echo " $LATEST_ALIAS"
echo "If the build fails, please 'docker pull linaroits/linkcheck'"
echo "and try again."
echo "************************************************************"
fi
if [ -z "$LATEST_ALIAS" ]; then
echo "******************************************************************"
echo "WARNING! It has not been possible to check that this is the latest"
echo " Docker image."
echo "******************************************************************"
fi
fi

#

0 comments on commit 0a8e336

Please sign in to comment.
You can’t perform that action at this time.