-
-
Save mekanoe/9404781 to your computer and use it in GitHub Desktop.
ct tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# ct - cURL then (un)tar | |
# for normal use, it replaces | |
# $ curl <tarball url> | tar -z?f - | |
# also has weird zip stuff that acts the same way. | |
# NOW WITH RPM+YUM SUPPORT | |
import posixpath | |
import subprocess | |
import sys | |
try: | |
import urlparse | |
except ImportError: | |
import urllib.parse as urlparse | |
try: | |
url = sys.argv[1] | |
except IndexError: | |
url = None | |
if url is None: | |
print("""ct - cURL then (un)tar | |
usage: ct <tarball url>""") | |
sys.exit(1) | |
# find the magic ending | |
base = posixpath.basename(urlparse.urlsplit(url).path) | |
file = base.split(".")[-1] | |
zip = False | |
rpm = False | |
caller = "curl --silent %s | tar -x%sf -" | |
if file == "gz" or file == "tgz": | |
type = "z" | |
elif file == "bz2" or file == "tbz2": | |
type = "j" | |
elif file == "xz" or file == "txz": | |
type = "J" | |
elif file == "lzma": | |
type = "lzma" | |
caller = "curl --silent %s | tar --lzma -xf -; echo \"%s\" > /dev/null" | |
elif file == "lz": | |
type = "lzip" | |
caller = "curl --silent %s | tar --lzip -xf -; echo \"%s\" > /dev/null" | |
elif file == "zip": | |
zip = True | |
elif file == "rpm": | |
rpm = True | |
else: | |
print("Unknown file ending, I have no idea how to handle this file.") | |
sys.exit(1) | |
if zip: | |
subprocess.call(("wget -q %s" % (url)).split(" ")) | |
subprocess.call(("unzip -qq %s -d %s" % (base, ".".join(base.split(".")[:-1]))).split(" ")) | |
subprocess.call(("rm %s" % (base)).split(" ")) | |
elif rpm: | |
subprocess.call(("sudo yum localinstall -y %s" % (url)).split(" ")) | |
else: | |
subprocess.call(caller % (url, type), shell=True) | |
if not rpm: | |
print("Extracted probably into %s." % ".".join(base.split(".")[:-1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment