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