From 79058810c2b827a482880cb4fa907bf19290fedf Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Mon, 13 Jul 2020 13:48:27 -0700 Subject: [PATCH] added uninstall invoke task to uninstall core files added with the invoke install command, beyond system packages --- tasks.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/tasks.py b/tasks.py index c2028f35..2f9bd556 100644 --- a/tasks.py +++ b/tasks.py @@ -29,10 +29,14 @@ class OsInfo: self.version: float = version -def get_python(c: Context) -> str: +def get_python(c: Context, warn: bool = False) -> str: with c.cd(DAEMON_DIR): - venv = c.run("poetry env info -p", hide=True).stdout.strip() - return os.path.join(venv, "bin", "python") + r = c.run("poetry env info -p", warn=warn, hide=True) + if r.ok: + venv = r.stdout.strip() + return os.path.join(venv, "bin", "python") + else: + return "" def get_pytest(c: Context) -> str: @@ -165,7 +169,7 @@ def install_ospf_mdr(c: Context, os_info: OsInfo, hide: bool) -> None: c.run("sudo make install", hide=hide) -def install_files(c: Context, hide: bool, prefix="/usr/local") -> None: +def install_files(c: Context, hide: bool, prefix: str = "/usr/local") -> None: # install all scripts python = get_python(c) bin_dir = Path(prefix).joinpath("bin") @@ -241,6 +245,47 @@ def install(c, dev=False, verbose=False): print("inv gui") +@task +def uninstall(c, dev=False, verbose=False, prefix="/usr/local"): + """ + uninstall core + """ + hide = not verbose + print("uninstalling core-gui") + with c.cd(GUI_DIR): + c.run("sudo make uninstall", hide=hide) + print("uninstalling vcmd") + with c.cd(VCMD_DIR): + c.run("sudo make uninstall", hide=hide) + print("cleaning build directory") + c.run("make clean", hide=hide) + c.run("./bootstrap.sh clean", hide=hide) + python = get_python(c, warn=True) + if python: + with c.cd(DAEMON_DIR): + if dev: + print("uninstalling pre-commit") + c.run("poetry run pre-commit uninstall", hide=hide) + print("uninstalling poetry virtual environment") + c.run(f"poetry env remove {python}", hide=hide) + + # remove installed files + bin_dir = Path(prefix).joinpath("bin") + for script in Path("daemon/scripts").iterdir(): + dest = bin_dir.joinpath(script.name) + print(f"uninstalling {dest}") + c.run(f"sudo rm -f {dest}", hide=hide) + + # install service + systemd_dir = Path("/lib/systemd/system/") + service_name = "core-daemon.service" + service_file = systemd_dir.joinpath(service_name) + if service_file.exists(): + print(f"uninstalling service {service_file}") + c.run(f"sudo systemctl disable {service_name}", hide=hide) + c.run(f"sudo rm -f {service_file}", hide=hide) + + @task def daemon(c): """