#! /bin/sh -e

#
# $Id: lr_inflate,v 1.24 2001/10/18 19:13:17 flacoste Exp $

#
# Copyright (C) 2000-2001 Stichting LogReport Foundation LogReport@LogReport.org
# 
#     This program is free software; you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation; either version 2 of the License, or
#     (at your option) any later version.
# 
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
# 
#     You should have received a copy of the GNU General Public License
#     along with this program (see COPYING); if not, check with
#     http://www.gnu.org/copyleft/gpl.html or write to the Free Software 
#     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
#

#

PROGRAM=lr_inflate

id="${LR_ID:-UNSET}"

tag="all all $id $PROGRAM"

if test $# -ne 1
then
    echo >&2 "$tag err give filename as arg"
    exit 1
fi

echo >&2 "$tag info started with '$@'"

file=$1

if [ ! -f "$file" ]; then
    echo >&2 "$tag err aborted, no file '$file' found"
    exit 1
fi

if test ! -d "$TMPDIR"
then
    if test -f "$TMPDIR"
    then
        echo >&2 "$tag err $TMPDIR is a file, it should be a dir, aborting"
        exit 1
    else
        mkdir $TMPDIR
    fi
fi

tmpfile=$TMPDIR/${PROGRAM}.$$.`date +%Y%m%d.%H%M%S`.${id}.log
ext=${file##*.}

if [ "$ext" = "gz" -o "$ext" = "Z" -o "$ext" = "ZIP" ]; then
    echo >&2 "$tag info inflating $file to $tmpfile"
    zcat $file > $tmpfile
    rm $file
else
    echo >&2 "$tag info moving $file to $tmpfile"
    mv $file $tmpfile
fi

echo $tmpfile

echo >&2 "$tag info stopped"


