diff options
Diffstat (limited to 'sys_init.py')
| -rw-r--r-- | sys_init.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/sys_init.py b/sys_init.py new file mode 100644 index 0000000..5bcd618 --- /dev/null +++ b/sys_init.py | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | |||
| 2 | #installs pip packages and lsof for debian | ||
| 3 | |||
| 4 | import subprocess | ||
| 5 | import sys | ||
| 6 | import os | ||
| 7 | import importlib | ||
| 8 | |||
| 9 | def check_os(): | ||
| 10 | if os.path.exists('/etc/os-release'): | ||
| 11 | with open('/etc/os-release', 'r') as f: | ||
| 12 | content = f.read().lower() | ||
| 13 | if 'debian' in content or 'ubuntu' in content: | ||
| 14 | return 'debian' | ||
| 15 | elif 'fedora' in content: | ||
| 16 | return 'fedora' | ||
| 17 | return None | ||
| 18 | |||
| 19 | def install_package(package): | ||
| 20 | try: | ||
| 21 | importlib.import_module(package) | ||
| 22 | print(f"{package} is already installed") | ||
| 23 | except ImportError: | ||
| 24 | try: | ||
| 25 | subprocess.check_call([sys.executable, "-m", "pip", "install", package]) | ||
| 26 | print(f"Successfully installed {package}") | ||
| 27 | except subprocess.CalledProcessError: | ||
| 28 | print(f"Failed to install {package}") | ||
| 29 | |||
| 30 | def install_lsof(): | ||
| 31 | os_type = check_os() | ||
| 32 | if os_type == 'debian': | ||
| 33 | try: | ||
| 34 | subprocess.check_call(['apt-get', 'update']) | ||
| 35 | subprocess.check_call(['apt-get', 'install', '-y', 'lsof']) | ||
| 36 | print("lsof installed successfully") | ||
| 37 | except subprocess.CalledProcessError: | ||
| 38 | print("Failed to install lsof") | ||
| 39 | else: | ||
| 40 | print("Not a Debian-based system, skipping lsof installation") | ||
| 41 | |||
| 42 | def setup(): | ||
| 43 | # Install pyinotify | ||
| 44 | install_package('pyinotify') | ||
| 45 | # Install lsof if on Debian | ||
| 46 | install_lsof() | ||
| 47 | |||
| 48 | if __name__ == "__main__": | ||
| 49 | setup() | ||
