#!/bin/sh

# Uncompress and/or untar a Starlab-format tar file in the current
# directory.  Assume first that the file is compressed with gzip.
# If no such file is found, look for an uncompressed file.

if [ $# = 0 ]; then

    set -- *s_tar*	; # Note: filename format assumed and no ls

    case "$1" in
    \**)
	echo $0: No tar files found >&2
	exit 1
	;;
    esac
    while [ $# -gt 1 ]; do shift; done
fi

tarfile="$1"

# Got GNU tar?

for GNUTAR in gnutar gtar tar; do
  if $GNUTAR 2>&1 | grep " --help" >/dev/null; then
    gnutar=$TAR
    break
  fi
done

echo Extracting tar file $tarfile

case "$tarfile@$GNUTAR" in
  *gz@|*Z@)	gunzip -c "$tarfile" | tar xpBof - ;;
  *@)		tar xopf "$tarfile" ;;
  *gz@*|*Z@*)	${GNUTAR} xpzf "$tarfile" ;;
  *@*)		${GNUTAR} xpf "$tarfile" ;;
esac
