#!/bin/sh
# NAME
#	extract-package.sh : extract tarball compressed by bzip2/gzip.
# VERSION
#	$Id$
# CHANGELOG
#	$Log$
# USAGE
#	extract-package tarball1 tarball2 ...
# COPYRIGHT
#  Copyright (C) 2000,2001 Steel Wheels Project.
#  This file is a apart of the papaya utilities. 
#  If you need the information of copyright of this file, see COPYING
#  file distributed with file or see http://www.asahi-net.or.jp/~em7t-hmd
#  web page.

tar_command="/bin/tar"
gzip_command="/usr/bin/gzip"
bzip2_command="/usr/bin/bzip2"

error(){
	echo "ERROR: $1" ;
	exit 1 ;
}

if test -z $tar_command ; then
	error "tar command required" ;
fi

if test -z $gzip_command ; then
	error "gzip command required" ;
fi

if test -z $bzip2_command ; then
	error "bzip2 command required" ;
fi

for TARG in $* ; do
	if test -f $TARG ; then
		case $TARG in
		  *.tar.gz) $gzip_command -dc $TARG | $tar_command xf - ;;
		  *.tgz) $gzip_command -dc $TARG | $tar_command xf - ;;
		  *.tar.bz2) $bzip2_command -dc $TARG | $tar_command xf - ;;
		  *) error "unknown package: \"$TARG\"" ;;
		esac
	else
		error "file \"$TARG\" is not found." ;
	fi
done

exit 0 ;

