#!/bin/sh

set -e

# vars



SKEL_LIST="_@_SKEL_LIST_@_"
DIVERSION_TEST_FILE="/etc/skel/.profile"


# Only for Alpha testers
DIVERSION_ORIG_FILE="$DIVERSION_TEST_FILE.orig"



case "$1" in
	configure)
	
	# system groups
	update-base-groups || true
	grep -q "$DIVERSION_TEST_FILE"  /var/lib/dpkg/diversions && echo "[INFO] .. diversion found! ...remove it!" && dpkg-divert --remove "$DIVERSION_TEST_FILE" || true
	[ ! -e $DIVERSION_ORIG_FILE ] || mv "$DIVERSION_ORIG_FILE" "$DIVERSION_TEST_FILE"
    
	ORIGINAL_UPGRADE_FILE="/etc/update-manager/release-upgrades"
	NEW_DIVERTED_FILE="/usr/share/lliurex-base-files/release-upgrades/release-upgrades.diverted"
	PKG="lliurex-base-files"

	if [ ! -L ${ORIGINAL_UPGRADE_FILE} ] ; then
    
		dpkg-divert --add --package ${PKG} --rename --divert "$NEW_DIVERTED_FILE" "$ORIGINAL_UPGRADE_FILE" || true
		if [ -e "${ORIGINAL_UPGRADE_FILE}" ]; then
			rm -rf "${ORIGINAL_UPGRADE_FILE}" || true
		fi

		ln -s /etc/update-manager/release-upgrades.lliurex $ORIGINAL_UPGRADE_FILE

	fi

	if [ -e "/etc/apt/apt.conf.d/99lliurex" ]; then
		rm -rf "/etc/apt/apt.conf.d/99lliurex" || true 
	fi

   ;;
   abort-upgrade|abort-remove|abort-deconfigure)
   ;;

   *)
      echo "postinst called with unknown argument $1" >&2
      exit 1
   ;;
esac

#DEBHELPER#

exit 0