39 lines
874 B
Nix
39 lines
874 B
Nix
{
|
|
writeShellApplication,
|
|
active,
|
|
distroFile,
|
|
|
|
curl,
|
|
minio-client,
|
|
packer,
|
|
|
|
...
|
|
}:
|
|
|
|
let
|
|
inherit (builtins) concatStringsSep map;
|
|
in writeShellApplication {
|
|
name = "cache-isos";
|
|
runtimeInputs = [
|
|
curl
|
|
minio-client
|
|
packer
|
|
];
|
|
text = ''
|
|
mc alias set storage "$STORAGE_URL" root "$MINIO_SECRET"
|
|
mkdir -p cache
|
|
'' + (concatStringsSep "\n" (
|
|
map (d: ''
|
|
url=$(echo var.iso.url | packer console -var-file="${distroFile d}" -config-type=hcl2 sources/)
|
|
sha=$(echo var.iso.checksum | packer console -var-file="${distroFile d}" -config-type=hcl2 sources/)
|
|
# shellcheck disable=SC2143
|
|
if [ -z "$(mc ls storage/isos/cache/ | grep "$sha")" ]; then
|
|
curl --retry 3 --retry-all-errors -o "cache/$sha.iso" "$url"
|
|
mc put "cache/$sha.iso" "storage/isos/cache/$sha.iso"
|
|
else
|
|
echo "Skipping ${d.distro} - cache/$sha.iso"
|
|
fi
|
|
'') active
|
|
));
|
|
}
|