From b747e65de17eb65f0390731371becbe3a958a3ce Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Wed, 6 Dec 2023 00:16:20 +0100 Subject: add install script and unit file reformat sources --- script/install.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 script/install.py (limited to 'script/install.py') diff --git a/script/install.py b/script/install.py new file mode 100644 index 0000000..e08f8c5 --- /dev/null +++ b/script/install.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +import re +import sys +from pathlib import Path + + +def install_service_unit(prefix): + project_path = Path(__file__).parents[1] + + if prefix == "usr": + install_path = Path("/etc/systemd/system") + elif prefix == "usr/local": + install_path = Path("/usr/local/lib/systemd/system") + else: + raise Exception("first arg must be one of `usr` or `usr/local`") + + def substitute(match): + if match[1] == "PROJECT_PATH": + return str(project_path) + else: + raise KeyError(match[1]) + + service_text_in = open( + project_path / "script" / "jwebmail.service.in", mode="r" + ).read() + service_text = re.sub("@(\w+)@", substitute, service_text_in, flags=re.ASCII) + + install_path.mkdir(0o755, True, True) + + open(install_path / "jwebmail.service", mode="w").write(service_text) + + +if __name__ == "__main__": + install_service_unit(sys.argv[1] if len(sys.argv) == 2 else '') -- cgit v1.2.3