Skip to content

Instantly share code, notes, and snippets.

@relaxdiego
Last active September 3, 2020 03:37
Show Gist options
  • Save relaxdiego/e5140c6fdd3d3647eec155f6a6e0db46 to your computer and use it in GitHub Desktop.
Save relaxdiego/e5140c6fdd3d3647eec155f6a6e0db46 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
bundle_name=${1:-'charmed-kubernetes'}
channel=${2:-'stable'}
architecture=${3:-'amd64'}
mkdir -p /tmp/${bundle_name}
cd /tmp/${bundle_name}
echo "Downloading ${bundle_name} metadata..."
curl "https://api.jujucharms.com/charmstore/v5/meta/bundle-metadata?id=${bundle_name}&channel=${channel}" > ${bundle_name}.json
# Get the charm names without the leading 'cs:' in the name
charm_names=$(cat ${bundle_name}.json | jq .["\"${bundle_name}\""] | jq -r .applications[].Charm[3:])
rm -f snaps-to-download.txt && touch snaps-to-download.txt
for charm_name in $charm_names; do
echo "Getting names of all resources for $charm_name..."
curl -s "https://api.jujucharms.com/charmstore/v5/${charm_name}/meta/resources?channel=${channel}" > /tmp/charm-resources.json
echo "Snaps used by $charm_name:"
cat /tmp/charm-resources.json | jq -r '.[] | select( .Path | contains(".snap")) | .Path | capture("(?<snap>.+).snap") | .snap' | tee -a snaps-to-download.txt
done
# Remove duplicates and convert to single line
snaps="$(cat snaps-to-download.txt | sort | uniq | tr '\n' ' ')"
# Fetch the complete snap archives (tar.gz)
sudo snap-store-proxy fetch-snaps ${snaps} --channel=${channel} --architecture=${architecture}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment