#!/bin/bash

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

## Compare calamares-settings-debian with derivative calamares settings.

set -x

difftool=meld

dir1="/etc/calamares"
dir2="etc/calamares"

# Function to compare files
compare_files() {
    local file1="$1"
    local file2="$2"
    if diff "${file1}" "${file2}" >/dev/null ; then
        true "no difference"
    else
        $difftool "${file1}" "${file2}"
    fi
}

# Iterate over the files and directories within the base directory
find "$dir1" -type f | while read -r file; do
    true "------------------------------------------------------------"
    # Construct the corresponding file path in the second directory
    true "file: $file"

    if [ "$extension" = ".dist" ]; then
        continue
    fi

    file2=${file/$dir1/$dir2}

    file2=$(echo "$file2" | str_replace ".dist-orig" ".dist")

    extension="${file##*.}"

    # Check if the corresponding file exists in the second directory
    if [ -f "./$file2" ]; then
        compare_files "$file" "${file2}"
    fi
    if [ -f "./${file2}.dist" ]; then
        compare_files "$file" "${file2}.dist"
    fi
done

compare_files /usr/bin/add-calamares-desktop-icon usr/bin/add-calamares-desktop-icon.dist
compare_files /usr/bin/install-debian usr/bin/install-host
compare_files /usr/share/applications/install-debian.desktop usr/share/applications/install-host.desktop

true
