#installs pip packages and lsof for debian import subprocess import sys import os import importlib def check_os(): if os.path.exists('/etc/os-release'): with open('/etc/os-release', 'r') as f: content = f.read().lower() if 'debian' in content or 'ubuntu' in content: return 'debian' elif 'fedora' in content: return 'fedora' return None def install_package(package): try: importlib.import_module(package) print(f"{package} is already installed") except ImportError: try: subprocess.check_call([sys.executable, "-m", "pip", "install", package]) print(f"Successfully installed {package}") except subprocess.CalledProcessError: print(f"Failed to install {package}") def install_lsof(): os_type = check_os() if os_type == 'debian': try: subprocess.check_call(['apt-get', 'update']) subprocess.check_call(['apt-get', 'install', '-y', 'lsof']) print("lsof installed successfully") except subprocess.CalledProcessError: print("Failed to install lsof") else: print("Not a Debian-based system, skipping lsof installation") def setup(): # Install pyinotify install_package('pyinotify') # Install lsof if on Debian install_lsof() if __name__ == "__main__": setup()