#!/bin/bash

if [[ "$DISPLAY" && "$(which Xdialog 2>&1 | grep -v "which: no")" ]]; then
	dialog="Xdialog"
else
	dialog="dialog"
fi

if [ ! -e "$1" ]; then
	$dialog --title "Not Found" --msgbox "\n$1\nFile not found\n" 0 0
	exit
fi

fext=${1##*.}

if [ $fext != "tgz" ] && [ $fext != "txz" ]; then
	$dialog --title "Not a Package?" --msgbox "\n$1\nDoes not appear to be a valid software package\n" 0 0
	exit
fi

# OK, this script is only accessible to root and installpkg
# will do it's usual package checks, so we can go ahead and call 
# installpkg, and run it in a term so folks can see what's doing...

xterm -e installpkg $1

if [ $? = 1 ]; then
	clear
	$dialog --title "Error..." \
        	--msgbox "$1\nwas not properly installed.\n\n" 0 0
else
	$dialog --title "Complete" \
        	--infobox "$1\nhas been installed.\n" 0 0 4000
fi
exit

