#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

## TODO: unfinished

#set -x
set -e
set -o pipefail
set -o errtrace

true "INFO: Currently running script: $BASH_SOURCE $@"
true "ERROR: Not implemented!"
exit 1

safe-rm -r -- /home/user/Downloads/temp
mkdir -- /home/user/Downloads/temp

## XXX: hardcoded path
pushd "$HOME/derivative-binary/aptrepo_remote"

while read -r line; do
   if ! read -r one two three _ <<< $line ; then
      printf '%s\n' "faulty line: '$line'"
   fi

   if [ "$one" = "Filename:" ]; then
      true
   else
      continue
   fi

   file_name="$(printf '%s\n' "$line" | str_replace "Filename: " "")"

   if printf '%s\n' "$file_name" | grep -q -- anon-meta-packages ; then
      continue
   fi

   dir_name="$(dirname -- "$file_name")"
   base_name="$(basename -- "$file_name")"
   pkg_name="$(printf '%s\n' "$base_name" | cut -d"_" -f1)"

   deb="$(ls "${dir_name}/${pkg_name}_"*".deb" | sort -r | head -1)"

   if [ "$file_name" = "$deb" ]; then
      continue
   fi

   if \
      diffoscope \
         --no-progress \
         --no-default-limit \
         --exclude-directory-metadata=recursive \
         --exclude=changelog.Debian \
         --exclude="*/changelog.Debian.gz" \
         --exclude=changelog \
         --exclude="*/changelog.gz" \
         --exclude=md5sums \
         --exclude="*/usr/share/man/*" \
         --html="/home/user/Downloads/temp/${pkg_name}.html" \
         "$file_name" "$deb" ; then
      continue
   fi
done < ./dists/trixie-testers/main/binary-amd64/Packages

# ./dists/trixie-developers/main/binary-amd64/Packages
