#!/bin/bash
{
set -e

cd /var/www/downloads/images
i=0
filter=''
for f in DietPi_RPi5-ARMv8-Bookworm.img DietPi_RPi234-ARMv8-Bookworm.img DietPi_RPi2-ARMv7-Bookworm.img DietPi_RPi1-ARMv6-Bookworm.img
do
	filter+=".os_list[$i].release_date = \"$(date -ur "$f.xz" '+%F')\" | "
	filter+=".os_list[$i].image_download_size = $(stat -c '%s' "$f.xz") | "
	filter+=".os_list[$i].image_download_sha256 = \"$(mawk '{print $1}' "$f.xz.sha256")\" | "
	filter+=".os_list[$i].extract_size = $(<"$f.size") | "
	filter+=".os_list[$i].extract_sha256 = \"$(mawk '{print $1}' "$f.sha256")\" | "
	((i++)) || :
done
jq "${filter% | }" rpi-imager.json > rpi-imager.json.new
mv rpi-imager.json.new rpi-imager.json
/root/cloudflare_clear_cache.sh rpi-imager.json
}
