mirror of https://github.com/coddrago/Heroku
Update __main__.py
parent
28ee0b9a6b
commit
202b801d2f
|
@ -16,30 +16,18 @@ import getpass
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import hashlib
|
||||||
|
|
||||||
from ._internal import restart
|
from ._internal import restart
|
||||||
|
|
||||||
if (
|
def get_file_hash(filename):
|
||||||
getpass.getuser() == "root"
|
hasher = hashlib.sha256()
|
||||||
and "--root" not in " ".join(sys.argv)
|
try:
|
||||||
and all(trigger not in os.environ for trigger in {"DOCKER", "GOORM", "NO_SUDO"})
|
with open(filename, "rb") as f:
|
||||||
):
|
hasher.update(f.read())
|
||||||
print("🚫" * 15)
|
return hasher.hexdigest()
|
||||||
print("You attempted to run Heroku on behalf of root user")
|
except FileNotFoundError:
|
||||||
print("Please, create a new user and restart script")
|
return None
|
||||||
print("If this action was intentional, pass --root argument instead")
|
|
||||||
print("🚫" * 15)
|
|
||||||
print()
|
|
||||||
print("Type force_insecure to ignore this warning")
|
|
||||||
print("Type no_sudo if your system has no sudo (Debian vibes)")
|
|
||||||
inp = input('> ').lower()
|
|
||||||
if inp != "force_insecure":
|
|
||||||
sys.exit(1)
|
|
||||||
elif inp == "no_sudo":
|
|
||||||
os.environ["NO_SUDO"] = "1"
|
|
||||||
print("Added NO_SUDO in your environment variables")
|
|
||||||
restart()
|
|
||||||
|
|
||||||
|
|
||||||
def deps():
|
def deps():
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
|
@ -57,12 +45,34 @@ def deps():
|
||||||
],
|
],
|
||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
|
with open(".requirements_hash", "w") as f:
|
||||||
|
f.write(get_file_hash("requirements.txt"))
|
||||||
|
|
||||||
|
if (
|
||||||
|
getpass.getuser() == "root"
|
||||||
|
and "--root" not in " ".join(sys.argv)
|
||||||
|
and all(trigger not in os.environ for trigger in {"DOCKER", "GOORM", "NO_SUDO"})
|
||||||
|
):
|
||||||
|
print("\U0001F6AB" * 15)
|
||||||
|
print("You attempted to run Heroku on behalf of root user")
|
||||||
|
print("Please, create a new user and restart script")
|
||||||
|
print("If this action was intentional, pass --root argument instead")
|
||||||
|
print("\U0001F6AB" * 15)
|
||||||
|
print()
|
||||||
|
print("Type force_insecure to ignore this warning")
|
||||||
|
print("Type no_sudo if your system has no sudo (Debian vibes)")
|
||||||
|
inp = input('> ').lower()
|
||||||
|
if inp != "force_insecure":
|
||||||
|
sys.exit(1)
|
||||||
|
elif inp == "no_sudo":
|
||||||
|
os.environ["NO_SUDO"] = "1"
|
||||||
|
print("Added NO_SUDO in your environment variables")
|
||||||
|
restart()
|
||||||
|
|
||||||
if sys.version_info < (3, 8, 0):
|
if sys.version_info < (3, 8, 0):
|
||||||
print("🚫 Error: you must use at least Python version 3.8.0")
|
print("\U0001F6AB Error: you must use at least Python version 3.8.0")
|
||||||
elif __package__ != "hikka": # In case they did python __main__.py
|
elif __package__ != "hikka":
|
||||||
print("🚫 Error: you cannot run this as a script; you must execute as a package")
|
print("\U0001F6AB Error: you cannot run this as a script; you must execute as a package")
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
import herokutl
|
import herokutl
|
||||||
|
@ -71,29 +81,35 @@ else:
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
import herokutl # noqa: F811
|
import herokutl # noqa: F811
|
||||||
|
|
||||||
if tuple(map(int, herokutl.__version__.split("."))) < (2, 0, 8):
|
if tuple(map(int, herokutl.__version__.split("."))) < (2, 0, 8):
|
||||||
raise ImportError
|
raise ImportError
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print("🔄 Installing dependencies...")
|
print("\U0001F504 Installing dependencies...")
|
||||||
deps()
|
deps()
|
||||||
restart()
|
restart()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from . import log
|
from . import log
|
||||||
|
|
||||||
log.init()
|
log.init()
|
||||||
|
|
||||||
from . import main
|
from . import main
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
print(f"{str(e)}\n🔄 Attempting dependencies installation... Just wait ⏱")
|
print(f"{str(e)}\n\U0001F504 Attempting dependencies installation... Just wait ⏱")
|
||||||
deps()
|
deps()
|
||||||
restart()
|
restart()
|
||||||
|
|
||||||
if "HIKKA_DO_NOT_RESTART" in os.environ:
|
if "HIKKA_DO_NOT_RESTART" in os.environ:
|
||||||
del os.environ["HIKKA_DO_NOT_RESTART"]
|
del os.environ["HIKKA_DO_NOT_RESTART"]
|
||||||
|
|
||||||
if "HIKKA_DO_NOT_RESTART2" in os.environ:
|
if "HIKKA_DO_NOT_RESTART2" in os.environ:
|
||||||
del os.environ["HIKKA_DO_NOT_RESTART2"]
|
del os.environ["HIKKA_DO_NOT_RESTART2"]
|
||||||
|
|
||||||
main.hikka.main() # Execute main function
|
prev_hash = None
|
||||||
|
if os.path.exists(".requirements_hash"):
|
||||||
|
with open(".requirements_hash", "r") as f:
|
||||||
|
prev_hash = f.read().strip()
|
||||||
|
|
||||||
|
if prev_hash != get_file_hash("requirements.txt"):
|
||||||
|
print("\U0001F504 Detected changes in requirements.txt, updating dependencies...")
|
||||||
|
deps()
|
||||||
|
restart()
|
||||||
|
|
||||||
|
main.hikka.main()
|
||||||
|
|
Loading…
Reference in New Issue