#! /bin/sh

set -e

# Load debconf
. /usr/share/debconf/confmodule

CFG_PATH='/etc/lazarus'
PKG_CFG_PATH="/etc/lazarus-${VERSION}"
LIB_DIR="/usr/lib/lazarus/${VERSION}"
MAN_DIR="/usr/share/man/man1"

# Debhelper code
#DEBHELPER#

USER_HAS_ENABLED_NEW_CONF="test -L ${CFG_PATH} -o  ! -e ${CFG_PATH}"

if ! ${USER_HAS_ENABLED_NEW_CONF}
then
	db_get lcl-utils${PACKAGESUFFIX}/rename_cfg
	if test "${RET}" = "true" -a -e ${CFG_PATH}
	then
		mv "${CFG_PATH}" "${CFG_PATH}.bak"
	fi
fi

if ${USER_HAS_ENABLED_NEW_CONF}
then
	UPDATE_CFG_FILE_ALTERNATIVES="--slave ${CFG_PATH} lazarus.cfg ${PKG_CFG_PATH}"
fi
# Add alternatives
update-alternatives \
	--install /usr/lib/lazarus/default lazarus ${LIB_DIR} ${PRIORITY} \
	${UPDATE_CFG_FILE_ALTERNATIVES} \
    --slave /usr/bin/lazbuild lazbuild ${LIB_DIR}/lazbuild \
    --slave ${MAN_DIR}/lazbuild.1.gz lazbuild.1.gz ${MAN_DIR}/lazbuild-${VERSION}.1.gz \
	--slave /usr/bin/lazres lazres ${LIB_DIR}/tools/lazres \
	--slave ${MAN_DIR}/lazre.1.gzs lazres.1.gz ${MAN_DIR}/lazres-${VERSION}.1.gz \
	--slave /usr/bin/lrstolfm lrstolfm ${LIB_DIR}/tools/lrstolfm \
	--slave ${MAN_DIR}/lrstolfm.1.gz lrstolfm.1.gz ${MAN_DIR}/lrstolfm-${VERSION}.1.gz \
	--slave /usr/bin/svn2revisioninc svn2revisioninc ${LIB_DIR}/tools/svn2revisioninc \
	--slave ${MAN_DIR}/svn2revisioninc.1.gz svn2revisioninc.1.gz ${MAN_DIR}/svn2revisioninc-${VERSION}.1.gz \
	--slave /usr/bin/updatepofiles updatepofiles ${LIB_DIR}/tools/updatepofiles \
	--slave ${MAN_DIR}/updatepofiles.1.gz updatepofiles.1.gz ${MAN_DIR}/updatepofiles-${VERSION}.1.gz
