#!/bin/sh

set -e

DPKG_CONFIG_FILE=/etc/dpkg/dpkg.cfg.d/50localepurge

#DEBHELPER#

if [ "$1" = purge ] && [ -e /usr/share/debconf/confmodule ]; then
    . /usr/share/debconf/confmodule
    db_purge
    rm -rf /var/cache/localepurge
    rm -f /etc/locale.nopurge
    if which ucf >/dev/null 2>&1 ; then
        ucf --debconf-ok --purge /etc/locale.nopurge
    else
        echo >&2 "/etc/locale.nopurge could not be purged because ucf was not found."
    fi
    if which ucfr >/dev/null 2>&1 ; then
        ucfr --purge localepurge /etc/locale.nopurge
    fi
    rm -f /etc/locale.nopurge.md5sum
    if [ -f "$DPKG_CONFIG_FILE.disabled" ] ; then
        echo "localepurge: Removing disabled auto-generated config file."
        rm -f "$DPKG_CONFIG_FILE.disabled"
    fi
    if [ -f "$DPKG_CONFIG_FILE" ] ; then
        echo "localepurge: Removing auto-generated config file."
        rm -f "$DPKG_CONFIG_FILE"
    fi
    DEBREINSTALL="$(tempfile).$$"

NEWLINE='\\n'
echo
echo "  To reinstall all the packages which localepurge has been taking care"
echo "  of before, you can use the following command:"
echo
echo "    apt-get --reinstall install \$(dpkg -S LC_MESSAGES | cut -d: -f1 | tr ', ' '${NEWLINE}' | sort -u)"
echo
# create a ready made shell script for further usage:

echo "apt-get -u --reinstall --fix-missing install \$(dpkg -S LC_MESSAGES | cut -d: -f1 | tr ', ' '${NEWLINE}' | sort -u)" > $DEBREINSTALL
mv -n $DEBREINSTALL /var/tmp/reinstall_debs.sh

echo "  For your further usage, the file \"/var/tmp/reinstall_debs.sh\""
echo "  contains an enhanced version of the command line printed out above."
echo
fi

