#!/bin/sh

[ -e "$1" ] || exit 1

export PATH=/bin:/usr/bin

if [ -x "/bin/file" -o -x "/usr/bin/file" ]; then
    uncompress=`file $1 | sed -n "s/.*\(gzip\|bzip2\).*/\1/p"`
else 
    ( echo $1 | grep -q '\.g?[zZ]$' ) && uncompress=gzip
    ( echo $1 | grep -q '\.bz2$' ) && uncompress=bzip2
fi

[ -z "$uncompress" ] && exit 2
if [ -z "$2" ]; then
    exec $uncompress -dc $1
else
    exec $uncompress -dc $1 > $2
fi
