2024-10-07 09:28:28 +03:00
|
|
|
import filecmp
|
|
|
|
import subprocess
|
|
|
|
import os
|
|
|
|
from time import sleep
|
2024-10-07 10:57:04 +03:00
|
|
|
from pathlib import Path
|
2024-10-07 09:28:28 +03:00
|
|
|
|
|
|
|
|
2024-10-11 00:21:08 +03:00
|
|
|
def install() -> None:
|
2024-10-17 12:27:32 +03:00
|
|
|
serviceDelivered = False
|
|
|
|
conkyDelivered = False
|
2024-10-11 00:21:08 +03:00
|
|
|
projectDir = Path(__file__).resolve().parent.parent
|
|
|
|
homeDir = Path(os.getenv("HOME"))
|
2024-10-09 15:54:41 +03:00
|
|
|
|
2024-10-11 09:37:34 +03:00
|
|
|
# Service file change for userspace
|
2024-10-16 13:14:12 +03:00
|
|
|
pythonPath = (
|
|
|
|
subprocess.check_output("which python3", shell=True).decode("utf-8").strip()
|
|
|
|
)
|
|
|
|
|
|
|
|
# Fix for weather service
|
2024-10-11 09:37:34 +03:00
|
|
|
with open(os.path.join(projectDir, "services/wthrc.service"), "r") as service:
|
|
|
|
lines = service.readlines()
|
2024-10-18 17:58:47 +03:00
|
|
|
lines[6] = "WorkingDirectory=" + os.path.join(projectDir, "src") + "\n"
|
|
|
|
lines[7] = (
|
2024-10-16 13:14:12 +03:00
|
|
|
"ExecStart=" + pythonPath + " " + os.path.join(projectDir, "src/main.py") + "\n"
|
2024-10-11 18:56:25 +03:00
|
|
|
)
|
2024-10-11 09:37:34 +03:00
|
|
|
with open(os.path.join(projectDir, "services/wthrc.service"), "w") as service:
|
|
|
|
service.writelines(lines)
|
|
|
|
|
2024-10-16 13:14:12 +03:00
|
|
|
# Fix for conky service
|
|
|
|
with open(os.path.join(projectDir, "services/conkyconf.service"), "r") as service:
|
|
|
|
lines = service.readlines()
|
|
|
|
lines[6] = "WorkingDirectory=" + os.path.join(projectDir, "src") + "\n"
|
|
|
|
lines[7] = (
|
|
|
|
"ExecStart="
|
|
|
|
+ pythonPath
|
|
|
|
+ " "
|
|
|
|
+ os.path.join(projectDir, "src/main.py -f")
|
|
|
|
+ "\n"
|
|
|
|
)
|
|
|
|
with open(os.path.join(projectDir, "services/conkyconf.service"), "w") as service:
|
|
|
|
service.writelines(lines)
|
|
|
|
|
2024-10-11 18:56:25 +03:00
|
|
|
serviceDirExist = os.path.isdir(os.path.join(homeDir, ".config/systemd/user/"))
|
2024-10-16 13:14:12 +03:00
|
|
|
services = ["wthrc.service", "conky.service", "conkyconf.service"]
|
2024-10-11 00:21:08 +03:00
|
|
|
if serviceDirExist:
|
2024-10-11 18:56:25 +03:00
|
|
|
delivered = filecmp.cmpfiles(
|
|
|
|
os.path.join(projectDir, "services/"),
|
|
|
|
os.path.join(homeDir, ".config/systemd/user/"),
|
|
|
|
services,
|
2024-10-11 00:21:08 +03:00
|
|
|
shallow=True,
|
|
|
|
)
|
2024-10-17 12:27:32 +03:00
|
|
|
if delivered[2] == [] and delivered[1] == []:
|
|
|
|
serviceDelivered = True
|
2024-10-09 15:54:41 +03:00
|
|
|
|
2024-10-17 12:27:32 +03:00
|
|
|
conkyDirExist = os.path.isdir(os.path.join(homeDir, ".config/conly/"))
|
|
|
|
if conkyDirExist:
|
|
|
|
delivered = filecmp.cmp(
|
|
|
|
os.path.join(projectDir, "services/conky.conf"),
|
|
|
|
os.path.join(homeDir, ".config/systemd/user/conky.conf"),
|
|
|
|
shallow=True,
|
|
|
|
)
|
|
|
|
if delivered:
|
|
|
|
conkyDelivered = True
|
|
|
|
|
|
|
|
if not serviceDelivered or not serviceDirExist:
|
|
|
|
subprocess.call(["sh", os.path.join(projectDir, "scripts/service_install.sh")])
|
|
|
|
if not conkyDelivered or not conkyDirExist:
|
|
|
|
subprocess.call(["sh", os.path.join(projectDir, "scripts/conky_install.sh")])
|
2024-10-11 00:21:08 +03:00
|
|
|
subprocess.call(["sh", os.path.join(projectDir, "scripts/runner.sh")])
|
2024-10-09 15:54:41 +03:00
|
|
|
|
2024-10-11 00:21:08 +03:00
|
|
|
sleep(5)
|