#!/bin/bash

# Pearl Repository Editor lets you edit repository lists
# Created by Paweł "pavroo" Pijanowski 2014/05/22
# Copyright 2014-2020 under the GNU GPL2 License
# Last update 2020/10/05

# 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

DIALOGMENU="`which zenity`"
TITLE="--title="
TEXT="--text="
FILESELECT="--file-selection --filename=/etc/apt/sources.list.d/pearl.list"
TITLETEXT="$LOCAL10"

if [ -f /usr/bin/pearl-editor ]; then
	PEARLEDITOR="pearl-editor"
else
	PEARLEDITOR="gnome-text-editor"
fi

EDITFILE=`$DIALOGMENU $TITLE"$TITLETEXT" $FILESELECT`

if [ "$?" != "0" ]; then
	exit 1
else
	$PEARLEDITOR $EDITFILE
	/usr/lib/pearl-aptus/bin/edit-repo-custom
	exit 0
fi

exit 0
