#!/bin/sh
# Extract a bulk in the background and get its exit status
# I had to asked www.experts-exchange.com to get this work :)
#
# Author: Eko M. Budi for Vector Linux
# License : GNU GPL
#
# $1 = bulk (tlz, tbz2, or bz2)
# 
# Set ROOT enviromental to change the destination
echo working >/tmp/working

if [ -z "$1" ]; then
  echo "Usage: install-bulk <bulk> [ROOT]"
  exit 1
fi

TAR=tar-1.13
$TAR --help 1> /dev/null 2> /dev/null
if [ ! $? = 0 ]; then
  TAR=tar
fi
ROOT=${ROOT:-/}
[ "$2" ] && ROOT="$2"
case ${1##*.} in
  tlz|lzm|lzma)
    lzmadec <$1 | $TAR -xp -C $ROOT > /tmp/setup.tar 2>&1
    STATUS=$?
    ;;
  bz2|tbz2|tbz)
    $TAR -xpjf $1 -C $ROOT > /tmp/setup.tar 2>&1
    STATUS=$?
    ;;
esac
echo $STATUS > /tmp/setup.status
sleep 1
echo done >/tmp/working
