#!/bin/bash

# Last update 2020/10/05 by pavroo

# get default's locale file
DEFLOCDIR="/usr/share/pearl/pearl-aptus"
if [ "`cat /etc/default/locale | grep LANG= | grep de`" != "" ]; then
. $DEFLOCDIR/de
elif [ "`cat /etc/default/locale | grep LANG= | grep el`" != "" ]; then
. $DEFLOCDIR/el
elif [ "`cat /etc/default/locale | grep LANG= | grep es`" != "" ]; then
. $DEFLOCDIR/es
elif [ "`cat /etc/default/locale | grep LANG= | grep fr`" != "" ]; then
. $DEFLOCDIR/fr
elif [ "`cat /etc/default/locale | grep LANG= | grep hu`" != "" ]; then
. $DEFLOCDIR/hu
elif [ "`cat /etc/default/locale | grep LANG= | grep id_ID`" != "" ]; then
. $DEFLOCDIR/id_ID
elif [ "`cat /etc/default/locale | grep LANG= | grep it`" != "" ]; then
. $DEFLOCDIR/it
elif [ "`cat /etc/default/locale | grep LANG= | grep ja`" != "" ]; then
. $DEFLOCDIR/ja
elif [ "`cat /etc/default/locale | grep LANG= | grep pl`" != "" ]; then
. $DEFLOCDIR/pl
elif [ "`cat /etc/default/locale | grep LANG= | grep pt_BR`" != "" ]; then
. $DEFLOCDIR/pt_BR
elif [ "`cat /etc/default/locale | grep LANG= | grep pt_PT`" != "" ]; then
. $DEFLOCDIR/pt_PT
elif [ "`cat /etc/default/locale | grep LANG= | grep ru`" != "" ]; then
. $DEFLOCDIR/ru
elif [ "`cat /etc/default/locale | grep LANG= | grep zh_CN`" != "" ]; then
. $DEFLOCDIR/zh_CN
else
. $DEFLOCDIR/en
fi

testroot="`whoami`"
if [ "$testroot" != "root" ]; then
	echo " Must be root... Exiting"
	exit 1
fi

DIALOG500="yad --window-icon=system-software-installer --width=500 --height=300 --center"
DIALOG="yad --window-icon=system-software-installer --width=450 --height=200 --center"
TITLE="--always-print-result --dialog-sep --image=system-software-installer --title="
TEXT="--text="
OKEXIT="--button=Ok:0 --button=$LOCAL24:1"
MSGBOX="--button=Ok:0"
TITLETEXT="APTus"
if [ -f /usr/bin/pearl-xterm ];then
	PEARLXTERM="/usr/bin/pearl-xterm"
else
	echo "pearl-xterm is missing... Exiting..."
	exit 1
fi

NONFREE=`vrms -s | cut -d "|" -f 1`

$DIALOG500 $TITLE"$LOCAL34" $OKEXIT $TEXT"$LOCAL35:\n\n$NONFREE \n\n$LOCAL36"

if [ "$?" != "0" ]; then
	$DIALOG $TITLE"$TITLETEXT" $MSGBOX $TEXT"$LOCAL37"
	exit 0
else
	$PEARLXTERM "apt-get remove $NONFREE"

	$DIALOG $TITLE"$TITLETEXT" $MSGBOX $TEXT"$LOCAL8"
	exit 0
fi

exit 0
