Skip to content
Merged

L #2

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions rq.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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"]:
Expand All @@ -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