summaryrefslogtreecommitdiff
path: root/sys_init.py
diff options
context:
space:
mode:
authorhc <hc@email.ch>2025-02-01 10:21:49 +0800
committerhc <hc@email.ch>2025-02-01 10:21:49 +0800
commit6e2bd1f5053f5244d1294ba5ae2c0ffc047743b6 (patch)
treefb1d970b1f952eb372a19d51e360e62c64d36ec6 /sys_init.py
firstcommit
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 @@
+
+#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()