From 200706459fd3b917770621b9b2b5e13d02601a20 Mon Sep 17 00:00:00 2001
From: dbh201 <47301809+dbh201@users.noreply.github.com>
Date: Sat, 17 Sep 2022 12:26:52 +0200
Subject: [PATCH] userland-unpack: support decompression of non-archive files

---
 tools/userland-unpack |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/tools/userland-unpack b/tools/userland-unpack
index c18c15e..b8db23a 100755
--- a/tools/userland-unpack
+++ b/tools/userland-unpack
@@ -59,9 +59,13 @@
 		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 = ""
@@ -71,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
 
@@ -114,6 +118,9 @@
 	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"])

--
Gitblit v1.9.3