#!/bin/sh
set -e

# Module configs under /etc/calamares/modules/ are also shipped by
# calamares-settings-ubuntu-common. Diversions let this flavor package
# install its copies without a dpkg overwrite error (not for kubuntu flavor;
# that is handled via Conflicts/Replaces in debian/control).
PKG="calamares-settings-suryaos"
BASE_DIR="/etc/calamares/modules"

mkdir -p "$BASE_DIR"

divert_add() {
  orig="$1"
  alt="$2"
  dpkg-divert --package "$PKG" --add --rename --quiet \
    --divert "$alt" "$orig" || true
}

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
"

case "$1" in
  install|upgrade)
    for f in $FILES; do
      ORIG="$BASE_DIR/$f"
      ALT="$BASE_DIR/$f.distrib"
      divert_add "$ORIG" "$ALT"
    done
    ;;
esac

exit 0
