diff --git a/Aptfile b/Aptfile new file mode 100644 index 0000000000..f8d43b1717 --- /dev/null +++ b/Aptfile @@ -0,0 +1 @@ +neofetch diff --git a/userbot/__init__.py b/userbot/__init__.py index cdb558c66b..c83cfb9282 100644 --- a/userbot/__init__.py +++ b/userbot/__init__.py @@ -2,7 +2,6 @@ import subprocess import sys, os import dotenv - dotenv.load_dotenv("config.env") BUILD_CHOICE=os.environ.get("BUILD_CHOICE","stable") subprocess.run(["rm", "-rf", "brains.check"], stdout=subprocess.PIPE) @@ -107,6 +106,7 @@ DB_URI = os.environ.get("DB_URI", None) SCREEN_SHOT_LAYER_ACCESS_KEY = os.environ.get("SCREEN_SHOT_LAYER_ACCESS_KEY", None) OPEN_WEATHER_MAP_APPID = os.environ.get("OPEN_WEATHER_MAP_APPID", None) + SUDO = os.environ.get("SUDO", None) if CONSOLE_LOGGER_VERBOSE: logging.basicConfig( format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", diff --git a/userbot/modules/package.py b/userbot/modules/package.py new file mode 100644 index 0000000000..fbb0749a08 --- /dev/null +++ b/userbot/modules/package.py @@ -0,0 +1,45 @@ +import os +import subprocess +import platform +from userbot import SUDO + +def _start_instalation(): + install_with = None + package_managers = ["pacman", "apt-get", "yum", "brew", "yaourt", "dnf", "homebrew", "eopkg", "snap"] + if "linux" in str(platform.system()).lower(): + for manager in package_managers: + try: + subprocess.check_call(f"which {manager}", shell=True, stderr=subprocess.STDOUT) + install_package(manager) + return + except: + continue + + + +def install_package(package_manager): + packages = [] + to_install = [] + with open("Aptfile") as file: + for line in file: + packages.append(line) + + for package in packages: + try: + subprocess.check_call(f"which {package}", shell=True, stderr=subprocess.STDOUT) + except: + to_install.append(package) + + if to_install: + if SUDO: + subprocess.Popen(f"echo {str(SUDO)} | sudo -S {str(package_manager)}" + + f" install -y {' '.join(to_install)}", shell=True) + else: + subprocess.Popen(f"{str(package_manager)} install -y {' '.join(to_install)}", + shell=True) + +try: + if not 'heroku' in os.environ['PATH']: + _start_instalation() +except: + _start_instalation()