Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Determine if a given version of Bash has a specific 'shopt' option using all available 'bash' image tags on Docker Hub
#!/bin/bash
# source: http://www.googlinux.com/list-all-tags-of-docker-image/index.html
# maybe API documentation?
# shellcheck disable=SC2086
REGISTRY=https://registry.hub.docker.com/v2/repositories/library
[[ $(uname -s) == Darwin ]] && SORT=gsort || SORT=sort
tags=()
image=${1:-bash}
option=${2:-direxpand}
# set CLEANUP=1 in the environment to remove all downloaded images
CLEANUP=${CLEANUP:-}
if test -t 1; then
YEP=$(tput bold)$(tput setaf 2) # bold, green
NOPE=$(tput bold)$(tput setaf 1) # bold, red
RESET=$(tput sgr0)
fi
readarray -t tags < <(
for (( i=1; $?==0; i++ )); do
curl -sL $REGISTRY/$image/tags/?page=$i \
| jq -r '.results[]["name"]' 2>&-
done \
| grep -v devel \
| $SORT -V
)
for tag in "${tags[@]}"; do
if docker run --rm bash:$tag bash -c "shopt | grep -q $option" 2>&-; then
echo "$YEP$tag$RESET: has '$option'"
else
echo "$NOPE$tag$RESET: doesn't have '$option'"
fi
(( CLEANUP )) && docker rmi bash:$tag 2>&-
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.