#!/bin/bash
# gunzip and bunzip2 script capabilities
# included tar options
# version 0.1
# TODO : add save path and save information for tar information
# 14 November 2005
# Duckz

E_NOARGS=65
OPTS=xf  # you can use xvf option for verbose or xf for clean layout.


if [ -z "$2" ]

then
        echo " Usage : `basename $0` -b/-g filename"
        exit $E_NOARGS
fi

if [ -z "$1" ]
	then
	echo " Missing options, please use -b (bunzip) or -g (gunzip) "
	exit $E_NOARGS


	elif [ "$1" = "-g" ] 
	then 
	

	g=1 
	
	elif [ "$1" = "-b" ] 
	then 
	
	b=1 
	
	else 
	
	w=1

fi

if [ "$g" = "1" ] 

	then

	echo "Starting extracting $2"
	
        tar -z$OPTS $2 &> /dev/null # remove &> /dev/null for displaying tar error messages, FIXME= can put save information to file.

		if [ "$?" = "0" ]
			then	
        			
        			echo "Finished extracting $2"
			else
    			   	
    			   	echo "Wrong option $1"
    			   	echo "Error extracting $2" 
    			   	echo "Use -b option instead for bzip format"
		fi
exit $E_NOARGS

fi

if [ "$b" = "1" ]
	then
	
	echo "Starting extracting $2"
	
		
        tar -j$OPTS $2 &> /dev/null # remove &> /dev/null for displaying tar error messages, FIXME= can put save information to file.
        
        	if [ "$?" = "0" ]

		then
        		
			echo "Finished extracting $2"
		
		else
        		
        		echo "Wrong option $1"
        		echo "Error extracting $2"
        		echo "Use -g option instead for gzip format"
		fi

exit $E_NOARGS

else
	if [ "$w" = "1" ] ; then 
		
		echo "Wrong option $1" 
		echo "Use -b (bzip) or -g (gzip) instead"
		echo "Error extracting $2"
		
		else
		
		echo "File error"
		echo "Support only .bz2 and .gz file"
		echo "Error extracting $2"
	fi
		
fi

exit $E_NOARGS
