userland-unpack revision 3293
62af8654f682ca4913636bae099bec0befab985ctrawick# CDDL HEADER START
62af8654f682ca4913636bae099bec0befab985ctrawick# The contents of this file are subject to the terms of the
62af8654f682ca4913636bae099bec0befab985ctrawick# Common Development and Distribution License (the "License").
1e557a77c091a1d2f2872872a7c20e9f2ffccbc1aaron# You may not use this file except in compliance with the License.
1e557a77c091a1d2f2872872a7c20e9f2ffccbc1aaron# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5e98e52df07f59be456af01ebf46d81defef2385trawick# See the License for the specific language governing permissions
5e98e52df07f59be456af01ebf46d81defef2385trawick# and limitations under the License.
5e98e52df07f59be456af01ebf46d81defef2385trawick# When distributing Covered Code, include this CDDL HEADER in each
7a95e47ff0d0e4306df0901d56131b49dca5691etrawick# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
7a95e47ff0d0e4306df0901d56131b49dca5691etrawick# If applicable, add the following below this CDDL HEADER, with the
1e557a77c091a1d2f2872872a7c20e9f2ffccbc1aaron# fields enclosed by brackets "[]" replaced with your own identifying
7a95e47ff0d0e4306df0901d56131b49dca5691etrawick# information: Portions Copyright [yyyy] [name of copyright owner]
b393bdb2e1eabbe4b9b37c5eaeeeca799b2eb324stoddard# CDDL HEADER END
6f912b4ad14f622aa8d57f887c8c745e13ff6dbfjerenkrantz# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe# unpack.py - an archive unpack utility
435c423bdcfa61ff871a9e289d1140f2bac839b8brianp# A simple program to uncompress and unpack source archive files into a target
435c423bdcfa61ff871a9e289d1140f2bac839b8brianp# directory and fix permissions if requested.
f65342c1467751310036d4f9d75f554eaaf01cc6wrowedef uncompress_unpack_commands(filename, verbose=False):
45613d36b9466a48def0498cffa07f48980720f8jerenkrantz if (re.search("(\.bz2|\.tbz|\.tbz2)$", filename) != None):
45613d36b9466a48def0498cffa07f48980720f8jerenkrantz elif (re.search("(\.gz|\.tgz)$", filename) != None):
741a54303329728b27fe347447a362e1c576135etrawick print "command: %s %s %s" % (uncompress, filename, unpack)
9f62694a8b4e2b88994a14555d144b3836b311cfstoddard# recurse down a directory tree opening permissions so that others may access
52489511342e4ff3fe399e57f29d38e5c4227bc8trawick# files in the tree.
b8daf4c5ea3d5bb2111b1b021de6d3cd891e403bcoar print "Usage: %s [-v|--verbose] [-f|--fix-permissions] [-r|--relocate-to (dir)] (file)" % (sys.argv[0].split('/')[-1])
26dfa083a1662d57ba7cc410eec4e0696b9be469wrowe filename = ((args[0] == '/') and "%s" or "../%s") % args[0]
26dfa083a1662d57ba7cc410eec4e0696b9be469wrowe uncompress, unpack = uncompress_unpack_commands(filename)
4760aa1f19600972cf531ad7da73c1ee5a0225cedougm # extract the archive contents
994c3fbc3335e8fe883b1ce4515efc0c85061cdfaaron print "cd %s ; %s %s%s" % (tempdir, uncompress, filename,
e93d563852e1fa7a8c73af3b807916b41942d2f6dreid os.system("cd %s ; %s %s%s" % (tempdir, uncompress, filename, unpack))
e93d563852e1fa7a8c73af3b807916b41942d2f6dreid # open up the permissions on what we extracted
525508562a53864b78cf8da91ac13be9c072bba7jerenkrantz # move everything in the tempdir here
f04ad0ba7fe0eea5ea7a92f852cef75747ab2090trawick # rename the tempdir and open it's permissions