ModernOSWeather/src/installer.py

72 lines
2.5 KiB
Python

import filecmp
import subprocess
import os
from time import sleep
from pathlib import Path
def install() -> None:
serviceDelivered = False
conkyDelivered = False
projectDir = Path(__file__).resolve().parent.parent
homeDir = Path(os.getenv("HOME"))
# Service file change for userspace
pythonPath = (
subprocess.check_output("which python3", shell=True).decode("utf-8").strip()
)
# Fix for weather service
with open(os.path.join(projectDir, "services/wthrc.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") + "\n"
)
with open(os.path.join(projectDir, "services/wthrc.service"), "w") as service:
service.writelines(lines)
# 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)
serviceDirExist = os.path.isdir(os.path.join(homeDir, ".config/systemd/user/"))
services = ["wthrc.service", "conky.service", "conkyconf.service"]
if serviceDirExist:
delivered = filecmp.cmpfiles(
os.path.join(projectDir, "services/"),
os.path.join(homeDir, ".config/systemd/user/"),
services,
shallow=True,
)
if delivered[2] == [] and delivered[1] == []:
serviceDelivered = True
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)