#!/bin/sh
set -e

PKG="calamares-settings-suryaos"
BASE_DIR="/etc/calamares/modules"

# Ensure the directory exists (safe if already present)
mkdir -p "$BASE_DIR"

divert_add() {
  orig="$1"
  alt="$2"
  # Add diversion and rename any existing file to the diverted path
  dpkg-divert --package "$PKG" --add --rename --quiet \
    --divert "$alt" "$orig" || true
}

# List of calamares module config files you own
FILES="
shellprocess_install_translations.conf
before_bootloader_context.conf
after_bootloader_context.conf
shellprocess_logs.conf
shellprocess@boot_deploy.conf
shellprocess@boot_reconfigure.conf
shellprocess@nomodeset.conf
shellprocess@aptsources.conf
kubuntu-calamares.desktop
"

for f in $FILES; do
  ORIG="$BASE_DIR/$f"
  ALT="$BASE_DIR/$f.distrib"
  divert_add "$ORIG" "$ALT"
done
divert_add "/usr/share/applications/kubuntu-calamares.desktop" "/usr/share/applications/kubuntu-calamares.desktop.distrib"

exit 0
