2021-02-26 09:38:18 +01:00
#!/bin/bash
OS_CODENAME = focal
OS_VERSION = 20.04
2021-03-02 12:12:10 +01:00
2021-02-26 09:38:18 +01:00
function get_streams ()
{
2021-03-02 14:39:19 +01:00
if [ - e " $streams " ]; then
return 0
fi
2021-02-26 09:38:18 +01:00
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 "
2021-03-02 14:39:19 +01:00
if [ ! - f " $streams " ]; then
return 1
fi
2021-02-26 09:38:18 +01:00
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 " )
}
2021-03-02 14:39:19 +01:00
function file_url ()
2021-03-02 12:12:10 +01:00
{
2021-03-02 14:39:19 +01:00
local release_version = " $ 1 "
local filename = " $ 2 "
2021-03-03 12:30:15 +01:00
local baseurl = " https://images.maas.io/ephemeral-v3/stable "
2021-03-03 12:21:27 +01:00
2021-03-02 14:39:19 +01:00
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 " )
2021-03-03 12:21:27 +01:00
if [ - n " $MAAS_DOWNLOAD_URL " ]; then
baseurl = " $MAAS_DOWNLOAD_URL "
fi
url = " $baseurl / $url "
2021-03-02 12:12:10 +01:00
}
2021-03-04 15:36:22 +01:00
function verify_only ()
{
local release_version = " $ 1 "
local fname = " $ 2 "
get_checksum " $release_version " " $fname "
sha256sum = $ ( sha256sum " $fname " | cut - d\ - f1 )
if [ " $sha256sum " == " $checksum " ]; then
return 0
fi
return 1
}
2021-02-26 09:38:18 +01:00
function download_and_verify ()
{
2021-03-02 14:39:19 +01:00
local release_version = " $ 1 "
local fname = " $ 2 "
file_url " $release_version " " $fname "
2021-02-26 09:38:18 +01:00
2021-03-04 15:36:22 +01:00
if [ - f " $fname " ]; then
if verify_only " $release_version " " $fname " ; then
echo " $fname already downloaded, skipping "
return 0
fi
echo " Deleting $fname "
rm - f " $fname "
fi
2021-02-26 09:38:18 +01:00
wget " $url " - O " $fname "
2021-03-04 15:36:22 +01:00
if verify_only " $release_version " " $fname " ; then
2021-02-26 09:38:18 +01:00
return 0
fi
2021-03-02 17:00:17 +01:00
echo " Checksum fail "
2021-03-02 14:39:19 +01:00
rm - f " $fname "
2021-02-26 09:38:18 +01:00
return 1
}
function cleanup_temp ()
{
if [ - f " $streams " ]; then
rm - f " $streams "
fi
}
# vim: set ft=sh: