-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.py
More file actions
executable file
·38 lines (31 loc) · 1.21 KB
/
uninstall.py
File metadata and controls
executable file
·38 lines (31 loc) · 1.21 KB
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
import os
import subprocess
import sys
import typing as tp
if __name__ == "__main__":
# check if running with sudo
if os.getuid() != 0:
print("This script must be executed with Root permissions.")
sys.exit()
# get own repository name
cwd: str = os.path.dirname(os.path.realpath(__file__))
project_name: str = cwd.split("/")[-1]
print(f"Uninstalling {project_name}.")
# find the systemd service file
systemd_service: str = [file for file in os.listdir() if file.endswith(".service")][0]
if not systemd_service:
print(f"Systemd service file not found in {cwd}. Exiting.")
sys.exit()
# commands to execute
commands: tp.List[str] = [
f"sudo systemctl stop {systemd_service}",
f"sudo systemctl disable {systemd_service}",
f"sudo rm /etc/systemd/system/{systemd_service}",
"sudo systemctl daemon-reload",
"rm -rf .venv",
"rm -f poetry.lock",
]
for command, i in zip(commands, range(len(commands))):
print(f"\nExecuting command {i + 1}/{len(commands)}: {command}")
subprocess.run(command, shell=True)
print(f"\nDaemon for the project {project_name} has been uninstalled from this machine.")