diff --git a/rq.py b/rq.py index c81d2e0..78c8a6d 100644 --- a/rq.py +++ b/rq.py @@ -1,6 +1,8 @@ import requests import sys import os +import subprocess +import tempfile url = "https://macpatch-registry.vercel.app/" print(len(sys.argv)) if len(sys.argv) >= 2: @@ -19,6 +21,34 @@ def search(name): return matches def download(id): + # Ask user for permissions + while True: + ex = input("Are you sure you want to install this patch? This will run code and cmd commands. Use C to see these commands (y/n/c) ") + if ex == "n": + print("Patch aborted") + exit(0) + elif ex == "c": + print("=======================================") + print("Commands:") + print("If the patch has prebuilt binaries:") + print("chmod +x [TEMPDIR]/[EXECUTABLE]") + print("cd [TEMPDIR]") + print("./[EXECUTABLE]") + print("Else:") + print("git clone [GITHUB]") + print("cd [TEMPDIR]/[REPO]") + print("chmod +x install.sh") + print("./install.sh") + print("For all:") + print("rm -rf [TEMPDIR]") + print("=======================================") + elif ex == "y": + break + else: + print("Invalid input") + + + tmp = tempfile.mkdtemp(prefix="hyperPatch_") r = requests.get(url + "patch/" + id) data = r.json() if data["downloadableExec"]: @@ -27,14 +57,18 @@ def download(id): # Download u = githubData["assets"][0]["browser_download_url"] r = requests.get(u) - with open(id, "wb") as f: + with open(os.path.join(tmp, id), "wb") as f: f.write(r.content) - os.system("chmod +x " + id) - os.system("./" + id) + print("CHMOD OUTPUT:", subprocess.run(["chmod +x " + os.path.join(tmp, id)], shell=True).stdout) + subprocess.run(["cd " + tmp + "&& ./" + id], shell=True) else: print("Not downloadable") # Try to clone - os.system("git clone " + data["github"]) - os.system("cd " + id + "&& chmod +x install.sh && ./install.sh") + print("GIT CLONE OUTPUT:", subprocess.run(["cd " + tmp + "&& git clone " + data["github"]], shell=True).stdout) + repoName = data["github"].split("/")[-1] + print("INSTALL SCRIPT OUTPUT:", subprocess.run(["cd" + os.path.join(tmp, repoName) + "&& chmod +x install.sh && ./install.sh"], shell=True)) + print("LIST:", subprocess.run(["ls " + tmp], shell=True).stdout) + print(tmp) + subprocess.run(["rm -rf " + tmp], shell=True) # https://api.github.com/repos/Stoppedwumm/halflife2patcher/releases/latest \ No newline at end of file