Skip to content

Instantly share code, notes, and snippets.

@gnanet
Created June 21, 2017 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnanet/46556aca7e6e2250f0191881be75a5c5 to your computer and use it in GitHub Desktop.
Save gnanet/46556aca7e6e2250f0191881be75a5c5 to your computer and use it in GitHub Desktop.
Retrieve the image URL of the latest version of a public available vagrant box
#!/bin/bash
# This script retrieves the imagefile URL for the latest version of a vagrant box that is public available over atlas
# it understands responses with multiple providers for the same version
#
# Based on https://blog.abysm.org/2016/04/hashicorp-atlas-external-images-location/
#
# IMPORTANT: Works only until box config as JSON response is available trough https://atlas.hashicorp.com
# SEE: https://www.vagrantup.com/docs/vagrant-cloud/vagrant-cloud-migration.html
# If the JSON URL changes this may be available from the docs: https://www.vagrantup.com/docs/boxes/versioning.html
# get jq from https://stedolan.github.io/jq/download/
if [ "$(which jq)" == "" ]; then echo "You need 'jq' for this script to function"; echo "get it from https://stedolan.github.io/jq/download/"; e
# provide the vagrant init boxname into the THEBOX variable ( for example \"ubuntu/trusty64\", \"centos/7\", etc )
#THEBOX="centos/7"
#THEBOX="ubuntu/trusty64"
THEBOX=
if [ "${THEBOX}" == "" ]; then echo "Please provide the vagrant init boxname into the THEBOX variable ( for example \"ubuntu/trusty64\", \"cento
BOXURLS=$(curl --silent --location "https://atlas.hashicorp.com/${THEBOX}" | jq -r '.versions[0].providers[].url')
for BOXURL in ${BOXURLS}
do
THEPROVIDER=$(echo ${BOXURL} | sed -e "s/.*providers.\(.*\)\.box.*/\1/g")
IMAGEURL=$(curl --silent --head ${BOXURL} | grep Location: | awk {' print $2 '})
echo -n "${THEPROVIDER} provider: "
echo "${IMAGEURL}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment