#!/bin/bash

TEXTDOMAIN=gkdebconf-term

DONTUSEMSG=$"This program is not to be used alone, it is a wrapper for dpkg-reconfigure"
DONTUSEMSG=$DONTUSEMSG"\n"$"used by gkdebconf, use it instead."

NEEDROOTMSG=$"To run dpkg-reconfigure I need root, please type your password:"

SUCMSG=$"dpkg-reconfigure has successfully finished..."

ERRMSG=$"dpkg-reconfigure has failed..."

KEYMSG=$"press enter to continue..."

if [ -z "$1" ] || [ -z "$2" ]; then
    echo -e $DONTUSEMSG
    exit 1;
fi 

if xhost | grep -q 'LOCAL:'; then
    XHOST_HAD_LOCAL=1
else
    xhost +local: > /dev/null 2>&1
    XHOST_HAD_LOCAL=0
fi

if [ "$UID" '!=' "0" ]; then
    echo -e $NEEDROOTMSG
    /bin/su -c "/usr/sbin/dpkg-reconfigure -f\"$1\" \"$2\""
else
    /usr/sbin/dpkg-reconfigure -f"$1" "$2"
fi

if [ "$XHOST_HAD_LOCAL" = "0" ]; then
    xhost -local: > /dev/null 2>&1
fi

if [ "$?" != "0" ]; then
    echo -e $ERRMSG
    echo $KEYMSG
    read N
else
    echo -e $SUCMSG
    echo $KEYMSG
    read N
fi
