Home | History | Annotate | Download | only in tools
      1 #!/bin/sh
      2 #
      3 # CDDL HEADER START
      4 #
      5 # The contents of this file are subject to the terms of the
      6 # Common Development and Distribution License (the "License").
      7 # You may not use this file except in compliance with the License.
      8 #
      9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10 # or http://www.opensolaris.org/os/licensing.
     11 # See the License for the specific language governing permissions
     12 # and limitations under the License.
     13 #
     14 # When distributing Covered Code, include this CDDL HEADER in each
     15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16 # If applicable, add the following below this CDDL HEADER, with the
     17 # fields enclosed by brackets "[]" replaced with your own identifying
     18 # information: Portions Copyright [yyyy] [name of copyright owner]
     19 #
     20 # CDDL HEADER END
     21 #
     22 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
     23 # Use is subject to license terms.
     24 #
     25 #ident	"@(#)unpack-archive.sh	1.1	08/03/26 SMI"
     26 #
     27 # Common script to unpack various source archives
     28 #
     29 FIND=${FIND:-/bin/find}
     30 XARGS=${XARGS:-/bin/xargs}
     31 CHMOD=${CHMOD:-/bin/chmod}
     32 
     33 case "${1}" in
     34 	*.bz2)
     35 		COMMAND=${BZIP:-/usr/bin/bzip2}
     36 		COMMAND="${COMMAND} ${DECOMP_OPTS:--dc} ${1}"
     37 		;;
     38 	*.gz)
     39 		COMMAND=${GZIP:-/usr/bin/gzip}
     40 		COMMAND="${COMMAND} ${DECOMP_OPTS:--dc} ${1}"
     41 		;;
     42 	*.Z)
     43 		COMMAND=${ZCAT:-/usr/bin/zcat}
     44 		COMMAND="${COMMAND} ${1}"
     45 		;;
     46 	*.zip)
     47 		COMMAND=${UNZIP:-/usr/bin/unzip}
     48 		COMMAND="${COMMAND} ${DECOMP_OPTS} ${1}"
     49 		;;
     50 esac
     51 
     52 case "${1}" in
     53 	*.tar.*)
     54 		COMMAND="${COMMAND} | ${TAR:-/usr/bin/tar}"
     55 		COMMAND="${COMMAND} ${TAR_OPTS:-oxpf} -"
     56 		;;
     57 esac
     58 
     59 /bin/sh -c "${COMMAND}"
     60 
     61 if [ $# -eq 2 -a -d "${2}" ] ; then
     62 	${FIND} ${2} -type d | ${XARGS} ${CHMOD} 0755
     63 	${FIND} ${2} -type f | ${XARGS} ${CHMOD} a+r
     64 fi
     65