#!/bin/bash

export TEXTDOMAIN=gkdebconf-term

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

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

SUCMSG=`gettext "dpkg-reconfigure has successfully finished..."`

ERRMSG=`gettext "dpkg-reconfigure has failed..."`

KEYMSG=`gettext "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
