1*cdf0e10cSrcweir#!/bin/sh
2*cdf0e10cSrcweir
3*cdf0e10cSrcweirEXTENSION=`expr "//$1" : '.*\/.*\.\(t.*\)'`
4*cdf0e10cSrcweir[ -z $EXTENSION ] && ( echo "Unable to determine file type"; exit 2 )
5*cdf0e10cSrcweir
6*cdf0e10cSrcweirBASEDIR=`dirname "$1"`
7*cdf0e10cSrcweirFOLDER=`basename "$1" ".$EXTENSION"`
8*cdf0e10cSrcweirNUM=1
9*cdf0e10cSrcweir
10*cdf0e10cSrcweirDESTPATH="$BASEDIR/$FOLDER"
11*cdf0e10cSrcweir
12*cdf0e10cSrcweirwhile [ -d "$DESTPATH" ]; do
13*cdf0e10cSrcweir  NUM=`expr $NUM + 1`
14*cdf0e10cSrcweir  DESTPATH="$BASEDIR/$FOLDER-$NUM"
15*cdf0e10cSrcweirdone
16*cdf0e10cSrcweir
17*cdf0e10cSrcweirmkdir "$DESTPATH"
18*cdf0e10cSrcweircd "$DESTPATH"
19*cdf0e10cSrcweir
20*cdf0e10cSrcweirif [ "$EXTENSION" = "tar.gz" -o "$EXTENSION" = "tgz" ]; then
21*cdf0e10cSrcweir  if [ -x /usr/bin/gzcat ]; then
22*cdf0e10cSrcweir    /usr/bin/gzcat "$1" | tar -xf -
23*cdf0e10cSrcweir  else
24*cdf0e10cSrcweir    tar -xzf "$1"
25*cdf0e10cSrcweir  fi
26*cdf0e10cSrcweirelif [ "$EXTENSION" = "tar.bz2" -o "$EXTENSION" = "tbz2" ]; then
27*cdf0e10cSrcweir  /usr/bin/bzcat "$1" | tar -xf -
28*cdf0e10cSrcweirelse
29*cdf0e10cSrcweir  echo "Unsupported type of archive"
30*cdf0e10cSrcweir  exit 2
31*cdf0e10cSrcweirfi
32*cdf0e10cSrcweir
33*cdf0e10cSrcweirUPDATE=`eval ls */update` && SUBFOLDER=`dirname $UPDATE` && mv $SUBFOLDER/* . && rmdir $SUBFOLDER && echo "$DESTPATH/update"
34