Marcel Telka
2024-04-07 00fdc1139b715cf3833e0c7fda58e0e112e5be2f
tools/userland-unpack
@@ -1,4 +1,4 @@
#!/usr/bin/python2.7
#!/usr/bin/python3.9
#
# CDDL HEADER START
#
@@ -20,7 +20,7 @@
# CDDL HEADER END
#
# Copyright (c) 2010, Oracle and/or it's affiliates.  All rights reserved.
# Copyright (c) 2018, Michal Nowak
# Copyright (c) 2018-2019, Michal Nowak
#
#
# unpack.py - an archive unpack utility
@@ -44,7 +44,7 @@
   elif (re.search("(\.Z)$", filename) != None):
      uncompress = "/usr/bin/uncompress -c"
   elif (re.search("(\.7z)$", filename) != None):
      uncompress = "/usr/bin/7z --s"
      uncompress = "/usr/bin/7z x"
   elif (re.search("(\.lz)$", filename) != None):
      uncompress = "/usr/bin/lzip -dc"
   elif (re.search("(\.xz)$", filename) != None):
@@ -53,13 +53,19 @@
      uncompress = "/usr/bin/unzip -qo"
   elif (re.search("(\.oxt)$", filename) != None):
      uncompress = "/usr/bin/unzip -qo"
   elif (re.search("(\.zst|\.tzst)$", filename) != None):
      uncompress = "/usr/bin/unzstd -c"
   elif (re.search("(\.gem)$", filename) != None):
      ruby_ver = os.getenv('RUBY_VERSION', '')
      uncompress = "/usr/ruby/" + ruby_ver + "/bin/gem unpack"
   unpack = " | gtar -xf -"
   # if the file is just compressed, redirect stdout to ./filename with
   # one less extension.
   unpack = " > ./" + '.'.join(os.path.basename(filename).split('.')[:-1])
   if (re.search("(\.zip)$", filename) != None):
   if (re.search("(\.tar\.[^\.]+|\.tgz|\.txz|\.tbz2?)$",filename) != None):
      unpack = " | gtar -xf -"
   elif (re.search("(\.zip)$", filename) != None):
      unpack = ""
   elif (re.search("(\.oxt)$", filename) != None):
      unpack = ""
@@ -69,7 +75,7 @@
      unpack = ""
   if (verbose == True):
      print "command: %s %s %s" % (uncompress, filename, unpack)
      print("command: %s %s%s" % (uncompress, filename, unpack))
   return uncompress, unpack
@@ -91,8 +97,8 @@
      if (stat.S_IMODE(st.st_mode) != mode):
         if (verbose == True):
            print "Changing %s from %4.4o to %4.4o" % (path,
                  stat.S_IMODE(st.st_mode), mode)
            print("Changing %s from %4.4o to %4.4o" % (path,
                  stat.S_IMODE(st.st_mode), mode))
         os.chmod(path, mode)
      if stat.S_ISDIR(st.st_mode):
@@ -100,7 +106,7 @@
def usage():
   print "Usage: %s [-v|--verbose] [-f|--fix-permissions] [-r|--relocate-to (dir)] (file)" % (sys.argv[0].split('/')[-1])
   print("Usage: %s [-v|--verbose] [-f|--fix-permissions] [-r|--relocate-to (dir)] (file)" % (sys.argv[0].split('/')[-1]))
   sys.exit(1)
def main():
@@ -112,11 +118,14 @@
   permissions = None
   relocate_to = None
   if len(sys.argv) == 1:
      usage()
   try:
      opts, args = getopt.getopt(sys.argv[1:], "fr:v",
         ["fix-permissions", "relocate-to=", "verbose"])
   except getopt.GetoptError, err:
      print str(err)
   except getopt.GetoptError as err:
      print(str(err))
      usage()
   for opt, arg in opts:
@@ -135,8 +144,8 @@
   # extract the archive contents
   if (verbose == True):   
      print "cd %s ; %s %s%s" % (tempdir, uncompress, filename,
                  unpack)
      print("cd %s ; %s %s%s" % (tempdir, uncompress, filename,
                  unpack))
   os.system("cd %s ; %s %s%s" % (tempdir, uncompress, filename, unpack))
   # open up the permissions on what we extracted
@@ -151,7 +160,7 @@
   else:
      # rename the tempdir and open it's permissions
      os.renames(tempdir, relocate_to)
      os.chmod(relocate_to, 0755)
      os.chmod(relocate_to, 0o755)
if __name__ == "__main__":