#!/bin/bash

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

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/sparky-testing.list"
TITLETEXT="Select a file of the repository list you would like to edit"
if [ -f /usr/bin/sparky-editor ]; then
	SPARKYEDITOR="sparky-editor"
else
	SPARKYEDITOR="gnome-text-editor"
fi

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

if [ "$?" != "0" ]; then

	exit 0

else

	$SPARKYEDITOR $EDITFILE
	/opt/tray/sparky-tray-edit

fi

exit 0
