#!/bin/bash

# deps: bash, coreutils, apt, dialog, grep, sudo
# + aptitude, nala (optional)
# Last update 2025/05/31.1 by pavroo

if [ -f /tmp/sparky-mgr ]; then
	rm -f /tmp/sparky-mgr
fi

if [ -f /tmp/sparky-mgr ]; then
	echo ""
	echo "  sparky-mgr file is locked!"
	echo "  clean it up before launchig it again!"
	echo ""
	sudo rm -f /tmp/sparky-mgr
fi

DIALOG="`which dialog`"
YESNO="--yesno "
HEIGHT="20"
WIDTH="80"
MENUHEIGHT="12"
TITLE="--title "
ENTRY="--inputbox "
MENU="--menu"
TEXT=""
TITLETEXT="Sparky Package Tool (SPT)"

sudo $DIALOG $TITLE"$TITLETEXT" $MENU $TEXT"\nChoose Package Manager Interface" $HEIGHT $WIDTH $MENUHEIGHT \
APT "Advanced Package Tool" \
Aptitude "Front-end to APT" \
Nala "Front-end for libapt-pkg" \
Exit "Exit" 2>/tmp/sparky-mgr

#FRONTEND=`cat /tmp/sparky-mgr`

if [ "$?" = "0" ]; then
	FRONTEND=`cat /tmp/sparky-mgr`
else
	clear
	exit 0
fi
#rm /tmp/choice.$$

if [ "$FRONTEND" = "APT" ]; then
	spta
elif [ "$FRONTEND" = "Aptitude" ]; then
	sptt
elif [ "$FRONTEND" = "Nala" ]; then
	sptn
else
	clear
	exit 0	
fi

exit 0
