#!/usr/bin/bash
filenames=("common*.tar.gz" "smartfacts*.tar.gz" "external_smartfacts_air_gapped*.tar.gz")
echo "Checking downloaded files..."
for f in ${filenames[@]}; do
        if [ ! -f $f ]; then
                echo "File \"$f\" not found. Please download it and copy it into the directory $(pwd)"
        fi
        failed=false
        sha256sum -c "$f.sha256" || failed=true
done
if [ "$failed" = true ]; then
        echo "FAILED"
        exit 1;
fi
echo "File check OK."

echo "Loading container images..."
for f in ${filenames[@]}; do
        tarfilename=${f%".gz"}
        echo $tarfilename
        echo "Importing $tarfilename"
        gzip -dkf "$f"
        sudo ctr image import "$tarfilename"
        rm "$tarfilename"
done
echo "Container images loaded."
