summaryrefslogtreecommitdiff
path: root/sys_init.py
diff options
context:
space:
mode:
Diffstat (limited to 'sys_init.py')
-rw-r--r--sys_init.py49
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
4import subprocess
5import sys
6import os
7import importlib
8
9def 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
19def 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
30def 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
42def setup():
43 # Install pyinotify
44 install_package('pyinotify')
45 # Install lsof if on Debian
46 install_lsof()
47
48if __name__ == "__main__":
49 setup()