#!/bin/bash

# This file is based on pavroo APTus script and changed by Elton Fabrício Ferreira "eltonfabricio10" 
# 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 now..."
	exit 1
fi

DIALOG="yad --window-icon=search --width=450 --height=150 --center"
TITLE="--always-print-result --dialog-sep --image=search --title="
TEXT="--text="
OKEXIT=" --button=Ok:0 --button=$LOCAL24:1 "
ENTRY="--entry "
ENTRYTEXT="--entry-text "
MSGBOX="--button=Ok:0"
TITLETEXT="APTus"
if [ -f /usr/bin/spterm ]; then
	PEARLXTERM="spterm -e"
elif [ -f /usr/bin/xterm ]; then
	PEARLXTERM="xterm -fa 'Monospace' -fs 12 -e"
elif [ -f /etc/alternatives/x-terminal-emulator ]; then
	PEARLXTERM="x-terminal-emulator -e"
else
	echo "Install and use xterm or x-terminal-emulator, but not tilda or rxvt,"
	echo "in a case of a problem with displaying terminal window."
	echo "Exiting..."
	exit 1
fi

PACK1=`$DIALOG $TITLE"$LOCAL101" $OKEXIT $ENTRY $TEXT"$LOCAL102"`

if [ "$?" != "0" ]; then
	exit 0
else
	$PEARLXTERM "apt list *$PACK1* -v && echo 'Press <ENTER> to exit...' && read"
	exit 0
fi

exit 0
