ModernOSWeather/src/installer.py

72 lines
2.5 KiB
Python
Raw Permalink Normal View History

import filecmp
import subprocess
import os
from time import sleep
2024-10-07 10:57:04 +03:00
from pathlib import Path
def install() -> None:
2024-10-17 12:27:32 +03:00
serviceDelivered = False
conkyDelivered = False
projectDir = Path(__file__).resolve().parent.parent
homeDir = Path(os.getenv("HOME"))
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"]
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,
shallow=True,
)
2024-10-17 12:27:32 +03:00
if delivered[2] == [] and delivered[1] == []:
serviceDelivered = True
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")])
subprocess.call(["sh", os.path.join(projectDir, "scripts/runner.sh")])
sleep(5)