1cdf0e10cSrcweir#!/bin/sh
2*9f22d7c2SAndrew Rist# *************************************************************
3*9f22d7c2SAndrew Rist#
4*9f22d7c2SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
5*9f22d7c2SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
6*9f22d7c2SAndrew Rist#  distributed with this work for additional information
7*9f22d7c2SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
8*9f22d7c2SAndrew Rist#  to you under the Apache License, Version 2.0 (the
9*9f22d7c2SAndrew Rist#  "License"); you may not use this file except in compliance
10*9f22d7c2SAndrew Rist#  with the License.  You may obtain a copy of the License at
11*9f22d7c2SAndrew Rist#
12*9f22d7c2SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
13*9f22d7c2SAndrew Rist#
14*9f22d7c2SAndrew Rist#  Unless required by applicable law or agreed to in writing,
15*9f22d7c2SAndrew Rist#  software distributed under the License is distributed on an
16*9f22d7c2SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17*9f22d7c2SAndrew Rist#  KIND, either express or implied.  See the License for the
18*9f22d7c2SAndrew Rist#  specific language governing permissions and limitations
19*9f22d7c2SAndrew Rist#  under the License.
20*9f22d7c2SAndrew Rist#
21*9f22d7c2SAndrew Rist# *************************************************************
22cdf0e10cSrcweir
23cdf0e10cSrcweirEXTENSION=`expr "//$1" : '.*\/.*\.\(t.*\)'`
24cdf0e10cSrcweir[ -z $EXTENSION ] && ( echo "Unable to determine file type"; exit 2 )
25cdf0e10cSrcweir
26cdf0e10cSrcweirBASEDIR=`dirname "$1"`
27cdf0e10cSrcweirFOLDER=`basename "$1" ".$EXTENSION"`
28cdf0e10cSrcweirNUM=1
29cdf0e10cSrcweir
30cdf0e10cSrcweirDESTPATH="$BASEDIR/$FOLDER"
31cdf0e10cSrcweir
32cdf0e10cSrcweirwhile [ -d "$DESTPATH" ]; do
33cdf0e10cSrcweir  NUM=`expr $NUM + 1`
34cdf0e10cSrcweir  DESTPATH="$BASEDIR/$FOLDER-$NUM"
35cdf0e10cSrcweirdone
36cdf0e10cSrcweir
37cdf0e10cSrcweirmkdir "$DESTPATH"
38cdf0e10cSrcweircd "$DESTPATH"
39cdf0e10cSrcweir
40cdf0e10cSrcweirif [ "$EXTENSION" = "tar.gz" -o "$EXTENSION" = "tgz" ]; then
41cdf0e10cSrcweir  if [ -x /usr/bin/gzcat ]; then
42cdf0e10cSrcweir    /usr/bin/gzcat "$1" | tar -xf -
43cdf0e10cSrcweir  else
44cdf0e10cSrcweir    tar -xzf "$1"
45cdf0e10cSrcweir  fi
46cdf0e10cSrcweirelif [ "$EXTENSION" = "tar.bz2" -o "$EXTENSION" = "tbz2" ]; then
47cdf0e10cSrcweir  /usr/bin/bzcat "$1" | tar -xf -
48cdf0e10cSrcweirelse
49cdf0e10cSrcweir  echo "Unsupported type of archive"
50cdf0e10cSrcweir  exit 2
51cdf0e10cSrcweirfi
52cdf0e10cSrcweir
53cdf0e10cSrcweirUPDATE=`eval ls */update` && SUBFOLDER=`dirname $UPDATE` && mv $SUBFOLDER/* . && rmdir $SUBFOLDER && echo "$DESTPATH/update"
54