Run scripts from the Internet more securely than `curl | bash` (experimental)
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import requests
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def launch(command, data):
|
|
|
|
if isinstance(command, str):
|
|
|
|
command = [command]
|
|
|
|
elif isinstance(command, tuple):
|
|
|
|
command = list(command)
|
|
|
|
elif not isinstance(command, list):
|
|
|
|
raise ValueError("`command` must be `list`, `tuple`, or `str`")
|
|
|
|
|
|
|
|
return subprocess.run(command, input=data)
|
|
|
|
|
|
|
|
|
|
|
|
def yn(question, options="yn"):
|
|
|
|
options = options.lower()
|
|
|
|
|
|
|
|
options_display = f"[{'/'.join(options)}]"
|
|
|
|
full_question = f"{question} {options_display} "
|
|
|
|
|
|
|
|
response = "WILL NEVER OCCUR IN OPTIONS"
|
|
|
|
while not response in options:
|
|
|
|
response = input(full_question).lower().strip()[0]
|
|
|
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
url = sys.argv[1]
|
|
|
|
|
|
|
|
content = requests.get(url).content
|
|
|
|
|
|
|
|
launch("less", content)
|
|
|
|
|
|
|
|
response = yn("Do you want to run this script?")
|
|
|
|
if response == "y":
|
|
|
|
launch("bash", content)
|
|
|
|
else:
|
|
|
|
print("Script not run.")
|