#!/bin/bash

## testing result in error
# https://www.reddit.com/r/debian/comments/auogk7/no_kernel_modules_found_when_trying_to_install/


script="update-debian-testing-netboot-image"
dest_dir=
export YOURMIRROR=ftp.no.debian.org # A CDN backed by cloudflare and fastly currently
export ARCH=amd64
export DIST=bullseye

path=rsync://"$YOURMIRROR"/debian/dists/$DIST

files=("-a $path/main/installer-${ARCH}/current/images/netboot/netboot.tar.gz"
"-La $path/main/installer-${ARCH}/current/images/SHA256SUMS"
"-La $path/Release"
"-La $path/Release.gpg")


for A in "${files[@]}"; do
echo -n "Rsync: ${A##*/}"
rsync --log-file=./rsync.log \
    --log-file-format="File changed! %f %i" \
     $A . 2>1 > /dev/null && echo " | done" ||  echo " | failed"
done
           

sha256sum -c <(awk '/netboot\/netboot.tar.gz/{print $1 " netboot.tar.gz"}' SHA256SUMS) || exit 1
# Must print: netboot.tar.gz: OK


sha256sum -c <(awk '/[a-f0-9]{64}[[:space:]].*main\/installer-'$ARCH'\/current\/images\/SHA256SUMS/{print $1 " SHA256SUMS"}' Release) || exit 1
# Must print `SHA256SUMS: OK

echo -n "tar ef: netboot.tar.gz"
tar -xf  netboot.tar.gz  --strip-components=2  ./debian-installer/ && echo " | done" ||  echo " | failed"