#!/bin/bash
# Last update September 16, 2024 by pavroo

# get default's locale file
DEFLOCDIR="/usr/share/sparky/sparky-aptus-appcenter"
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
	if [ "`cat /etc/default/locale | grep LANG= | grep es_AR`" != "" ]; then
. $DEFLOCDIR/es_AR
	else
. $DEFLOCDIR/es_ES
	fi
elif [ "`cat /etc/default/locale | grep LANG= | grep fi`" != "" ]; then
. $DEFLOCDIR/fi
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 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 uk`" != "" ]; then
. $DEFLOCDIR/uk
elif [ "`cat /etc/default/locale | grep LANG= | grep zh_CN`" != "" ]; then
. $DEFLOCDIR/zh_CN
else
. $DEFLOCDIR/en
fi

DIALOG="yad --window-icon=/usr/share/pixmaps/sparky-aptus-appcenter.png --width=450 --height=350 --fixed --center"
TITLE="--always-print-result --dialog-sep --image=/usr/share/pixmaps/sparky-aptus-appcenter.png --title="
TITLETEXT="APTus AppCenter"
MSGBOX="--button=Ok:0"
TEXT="--text="
DIALOGZEN="zenity --progress --pulsate --auto-close --auto-kill --no-cancel --width=450 --height=120"
TITLEZEN="--title="
TESTROOT="`whoami`"
if [ "$TESTROOT" != "root" ]; then
	echo "Must be root... Exiting now..."
	exit 1
fi

# check connection
PINGTEST0=$(ping -c 1 debian.org | grep [0-9])
PINGTEST1=$(ping -c 1 sparkylinux.org | grep [0-9])

if [ "$PINGTEST0" = "" ] || [ "$PINGTEST1" = "" ]; then
	$DIALOG $TITLE"$TITLETEXT" $MSGBOX $TEXT"\n$LOCAL003\n\n$LOCAL084"
else
	if [ ! -f /tmp/appcenter-firstrun ]; then
		apt-get update | $DIALOGZEN $TITLEZEN"$TITLETEXT" $TEXT"\n$LOCAL085 $LOCAL086\n"
		touch /tmp/appcenter-firstrun
	fi
fi

cd /usr/lib/sparky-aptus-appcenter
./aptus-appcenter

exit 0
