Created
April 26, 2023 14:16
-
-
Save tommie/f4528a7da1af9d8228c385e175462faa to your computer and use it in GitHub Desktop.
Downloading Bottlerocket OS image files without tuftool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bkadm_metadata_url=https://updates.bottlerocket.aws/2020-07-07 | |
bkadm_targets_url=https://updates.bottlerocket.aws/targets | |
# E.g. get_bottlerocket_url 1.26 x86_64 '1\.13\..*' | |
get_bottlerocket_url() { | |
local kubernetes_ver=$1 arch=$2 ver_regex=$3 | |
shift 3 | |
local variant="metal-k8s-$kubernetes_ver" | |
local metadata_url="$bkadm_metadata_url/$variant/$arch" | |
local snapshot_ver | |
snapshot_ver=$(wget -q -O- "$metadata_url/timestamp.json" | jq -r '.signed.meta."snapshot.json".version') | |
if [ -z "$snapshot_ver" ]; then | |
FATAL "Failed to find TUF snapshot version in '$metadata_url/timestamp.json'." | |
fi | |
local targets_ver | |
targets_ver=$(wget -q -O- "$metadata_url/$snapshot_ver.snapshot.json" | jq -r '.signed.meta."targets.json".version') | |
if [ -z "$targets_ver" ]; then | |
FATAL "Failed to find TUF targets version in '$metadata_url/$snapshot_ver.snapshot.json'." | |
fi | |
local target | |
target=$(wget -q -O- "$metadata_url/$targets_ver.targets.json" | latest_target "$variant-$arch" "$ver_regex") | |
if [ -z "$target" ]; then | |
FATAL "Failed to find TUF target URL in '$metadata_url/$targets_ver.targets.json'." | |
fi | |
local length sha256 fname | |
read length sha256 fname <<<"$target" | |
echo "$length $sha256 $bkadm_targets_url/$sha256.$fname" | |
} | |
# Parses a targets.json file to extract the latest matching image. | |
latest_target() { | |
local variant="${1//./\\\\.}" | |
local ver_regex="${2:-.*}" | |
shift 2 | |
ver_regex=${ver_regex//\\/\\\\} | |
jq -r '[.signed.targets | to_entries | .[] | select(.key | test("bottlerocket-'"$variant-v$ver_regex"'\\.img\\.lz4"))] | sort_by(.key) | .[-1] | ((.value.length | tostring) + " " + .\ | |
value.hashes.sha256 + " " + .key)' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment