feat: add basic functions for maas images
This commit is contained in:
parent
c0a928cc32
commit
e90922002f
71
maas-images.inc
Normal file
71
maas-images.inc
Normal file
|
@ -0,0 +1,71 @@
|
|||
#!/bin/bash
|
||||
|
||||
OS_CODENAME=focal
|
||||
OS_VERSION=20.04
|
||||
|
||||
function get_streams()
|
||||
{
|
||||
streams="$(mktemp)"
|
||||
wget -qO "$streams" https://images.maas.io/ephemeral-v3/stable/streams/v1/com.ubuntu.maas:stable:v3:download.json
|
||||
}
|
||||
|
||||
|
||||
function find_oldest()
|
||||
{
|
||||
# find locally
|
||||
return 0
|
||||
}
|
||||
|
||||
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"
|
||||
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 download_and_verify()
|
||||
{
|
||||
local url="$1"
|
||||
local checksum="$2"
|
||||
local fname="$3"
|
||||
|
||||
wget "$url" -O "$fname"
|
||||
sha256sum=$(sha256sum "$fname")
|
||||
if [ "$sha256sum" == "$checksum" ]; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
function cleanup_temp()
|
||||
{
|
||||
if [ -f "$streams" ]; then
|
||||
rm -f "$streams"
|
||||
fi
|
||||
}
|
||||
|
||||
function download_files()
|
||||
{
|
||||
download kernel
|
||||
download initrd
|
||||
download squashfs
|
||||
|
||||
dd if=squashfs of="$partition" bs=1M
|
||||
|
||||
create_options_file
|
||||
update_default
|
||||
delete_oldest_if_needed
|
||||
update_onerror_second_youngest
|
||||
}
|
||||
|
||||
# vim: set ft=sh:
|
26043
tests/data/streams.json
Normal file
26043
tests/data/streams.json
Normal file
File diff suppressed because it is too large
Load Diff
41
tests/maas.sh
Executable file
41
tests/maas.sh
Executable file
|
@ -0,0 +1,41 @@
|
|||
#!/bin/bash
|
||||
|
||||
function test_stream()
|
||||
{
|
||||
local mimetype
|
||||
get_streams
|
||||
mimetype="$(file -b --mime-type "$streams")"
|
||||
assertEquals "$mimetype" "application/json"
|
||||
cleanup_temp
|
||||
}
|
||||
|
||||
function test_latest_maas_id()
|
||||
{
|
||||
get_latest_maas_id
|
||||
assertEquals "20210223" "$release_version"
|
||||
}
|
||||
|
||||
function test_checksum()
|
||||
{
|
||||
get_checksum 20210223 manifest
|
||||
assertEquals "cf395299f1337f6ea69a86f70d76fb89b8a41274bbbe7047af43614a867a4af2" "$checksum"
|
||||
}
|
||||
|
||||
#function test_download()
|
||||
#{
|
||||
# download_and_verify https://images.maas.io/ephemeral-v3/stable/${OS_CODENAME}/amd64/${id}/squashfs
|
||||
# assertEquals "$?" 0
|
||||
#}
|
||||
|
||||
function oneTimeSetUp()
|
||||
{
|
||||
. maas-images.inc
|
||||
}
|
||||
|
||||
function setUp()
|
||||
{
|
||||
export streams=tests/data/streams.json
|
||||
}
|
||||
|
||||
# Load shUnit2.
|
||||
. /usr/bin//shunit2
|
Loading…
Reference in New Issue
Block a user