summaryrefslogtreecommitdiff
path: root/sys_init.py
blob: 5bcd6181e1d5a3af207df42248c2b2c3fdfdd782 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

#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()