-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.py
More file actions
executable file
·61 lines (52 loc) · 1.66 KB
/
Copy pathinstaller.py
File metadata and controls
executable file
·61 lines (52 loc) · 1.66 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
import sys
import os
def check_python_version():
try:
x, y, z, a, b = sys.version_info
ver = str(x) + str(y)
if int(ver) < 36:
print("\nThis application requires Python 3.6 or greater.\nhttps://www.python.org/downloads/\n")
exit(0)
except PermissionError as p:
print("woops!, you need to run this as root.\n" + str(p))
exit(1)
except Exception as e:
print("Error! in check_python_version: " + str(e))
def write_unit_file(systemd_file):
try:
with open("/etc/systemd/system/claymore.service", "w") as file:
file.writelines(systemd_file)
except PermissionError as p:
print("\nwoops!, you need to run the installer as root.\n")
exit(1)
except Exception as e:
print("Error! in write_unit_file: " + str(e))
def systemd_unit_file():
systemd_file = [
"[Unit]",
"\nDescription=Claymore",
"\n[Service]",
"\nType=simple",
"\nExecStartPre=/bin/sleep 4",
"\nExecStart=/usr/bin/env python3 " + os.getcwd() + "/claymore.py",
"\nRestart=always",
"\n[Install]",
"\nWantedBy=multi-user.target\n"
]
return systemd_file
def enable_service():
try:
os.system("systemctl enable claymore.service")
os.system("systemctl restart claymore.service")
except PermissionError as p:
print("woops!, you need to run this as root.\n" + str(p))
exit(1)
except Exception as e:
print("Error! in enable_service: " + str(e))
def main():
check_python_version()
write_unit_file(systemd_unit_file())
enable_service()
if __name__ == '__main__':
main()