sysdeploy/maas-images.inc

73 lines
1.8 KiB
PHP
Raw Normal View History

#!/bin/bash
OS_CODENAME=focal
OS_VERSION=20.04
2021-03-02 12:12:10 +01:00
function get_streams()
{
if [ -e "$streams" ]; then
return 0
fi
streams="$(mktemp)"
wget -qO "$streams" https://images.maas.io/ephemeral-v3/stable/streams/v1/com.ubuntu.maas:stable:v3:download.json
}
function get_latest_maas_id()
{
if [ ! -f "$streams" ]; then
return 1
fi
release_version=$(jq -r '.products[]|select(.version=="'"$OS_VERSION"'" and .arch=="amd64" and .kflavor=="generic" and .subarch=="ga-'"$OS_VERSION"'")|.versions|keys|max' \
"$streams")
}
function get_checksum()
{
local release_version="$1"
local filename="$2"
if [ ! -f "$streams" ]; then
return 1
fi
checksum=$(jq -r '.products[]|select(.version=="'"$OS_VERSION"'" and .arch=="amd64" and .kflavor=="generic" and .subarch=="ga-'"$OS_VERSION"'").versions."'"$release_version"'".items."'"$filename"'".sha256' \
"$streams")
}
function file_url()
2021-03-02 12:12:10 +01:00
{
local release_version="$1"
local filename="$2"
if [ ! -f "$streams" ]; then
return 1
fi
url=$(jq -r '.products[]|select(.version=="'"$OS_VERSION"'" and .arch=="amd64" and .kflavor=="generic" and .subarch=="ga-'"$OS_VERSION"'").versions."'"$release_version"'".items."'"$filename"'".path' \
"$streams")
url="https://images.maas.io/ephemeral-v3/stable/$url"
2021-03-02 12:12:10 +01:00
}
function download_and_verify()
{
local release_version="$1"
local fname="$2"
file_url "$release_version" "$fname"
checksum "$release_version" "$fname"
wget "$url" -O "$fname"
sha256sum=$(sha256sum "$fname")
if [ "$sha256sum" == "$checksum" ]; then
return 0
fi
rm -f "$fname"
return 1
}
function cleanup_temp()
{
if [ -f "$streams" ]; then
rm -f "$streams"
fi
}
# vim: set ft=sh: