#!/bin/bash

# This script removes all user's cache
# 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

DIALOG="yad --window-icon=application-x-trash --width=450 --height=150 --center"
TITLE="--always-print-result --dialog-sep --image=application-x-trash --title="
TEXT="--text="
OKEXIT=" --button=Ok:0 --button=$LOCAL24:1 "
MSGBOX="--button=Ok:0"
TITLETEXT="APTus"

USER1000=`cat /etc/passwd | grep 1000 | cut -f1 -d:`
USER0=`users`
if [ "$USER1000" = "$USER0" ]; then
	TARGETUSER="$USER1000"
else
	$DIALOG $TITLE"$TITLETEXT" $MSGBOX $TEXT"$LOCAL103\n\n$LOCAL24"
	exit 1
fi

if [ -d /home/$TARGETUSER/.cache ]; then
	$DIALOG $TITLE"$TITLETEXT" $OKEXIT $TEXT"$LOCAL104 $TARGETUSER ?"
	if [ "$?" = "0" ]; then
		rm -frd /home/$TARGETUSER/.cache/*
	fi
else
	exit 1
fi

exit 0
