-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
91 lines (72 loc) · 2.43 KB
/
setup.py
File metadata and controls
91 lines (72 loc) · 2.43 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import platform
import re
import uuid
from Config import Config
import os
import shutil
import geocoder
import websocket
# noinspection DuplicatedCode
def rmtree_hard(path, _prev=None):
try:
shutil.rmtree(path)
except PermissionError as e:
if e == _prev:
return
match = re.search(r"Access is denied: '(.*)'", str(e))
if match:
file_path = match.group(1)
os.chmod(file_path, 0o777)
# Delete the file
os.remove(file_path)
rmtree_hard(path, _prev=e)
else:
raise e
def setup_database():
if not os.path.exists("./temp"):
os.makedirs("./temp")
init_temp_path = os.path.join("./temp", str(uuid.uuid4()))
shutil.copy2("./Skills/__init__.py", init_temp_path)
for file in os.listdir("./Skills"):
if os.path.isdir(os.path.join(os.path.abspath("./Skills"), file)):
rmtree_hard(os.path.join(os.path.abspath("./Skills"), file))
shutil.move(init_temp_path, "./Skills/__init__.py")
def get_unique_identifier():
if platform.system() == "Linux":
try:
with open("/proc/cpuinfo", "r") as f:
lines = f.readlines()
for line in lines:
if line.startswith("Serial"):
return line.split(":")[-1].strip()
except Exception as e:
print(f"An error occurred: {e}")
return None
elif platform.system() == "Windows":
import wmi
c = wmi.WMI()
try:
system_info = c.Win32_ComputerSystemProduct()[0]
serial_number = system_info.UUID
if serial_number and serial_number != "Default string":
return serial_number.strip()
else:
return None
except Exception as e:
print(f"An error occurred: {e}")
return None
else:
print("Unsupported operating system.")
return None
def setup():
config = Config()
if platform.system() == "Windows":
os.system("sudo pip3 install WMI")
setup_database()
g = geocoder.ip("me")
config["CITY"] = g.city
config["COUNTRY"] = g.country
config["UID"] = get_unique_identifier()
config["CURRENT_STAGE"] = 2
websocket_url = "wss://websocket.ballbert.com:8765"
ws = websocket.create_connection(websocket_url, header={"UID": config["UID"], "User-Agent": "Device-Setup"})