#!/bin/bash
#
# c2009-2024 by Paul Sherman for Absolute Linux

if [[ "$DISPLAY" && "$(which Xdialog 2>&1 | grep -v "which: no")" ]]; then
	dialog="Xdialog"
else
	dialog="dialog"
fi
if [ ! -e "$1" ]; then
	$dialog --title "No File Specified" --msgbox "\nMust be passed a TGZ file\n" 10 36
	exit
fi


ext=${1##*.}
if [ ! "$ext" == "tgz" ]; then
	$dialog --title "Wrong File Type..." \
        	--msgbox "The file:\n$1\ndoes not seem to be a TGZ file.\n\n" 0 0
	exit 0
fi

ret=`which tgz2txz`
if [ ! "$ret" == "/usr/local/bin/tgz2txz" ]; then
	$dialog --title "Missing..." \
        	--msgbox "To auto-convert tgz2txz needs to be installed.\n\n" 0 0
	exit 0
fi

pth=`dirname "$1"`
cd $pth

tgz2txz "$1"

if [ $? = 1 ]; then
   clear
	$dialog --title "Error..." \
        	--msgbox "$1\nwas not properly converted.\n\n" 0 0
else
	$dialog --title "Complete" \
        	--infobox "\nConversion to TXZ has finished.\n" 0 0 4000
fi
exit
