diff --git a/routlin/install.py b/routlin/install.py index d191423..b0bc3c1 100644 --- a/routlin/install.py +++ b/routlin/install.py @@ -235,29 +235,32 @@ def _set_env_var(content, key, value): return new -def setup_docker_compose(): +def _dash_already_configured(): + if not COMPOSE_FILE.exists(): + return False + return bool(re.search(r"^\s*- SECRET_KEY=\S", COMPOSE_FILE.read_text(), re.MULTILINE)) + +def setup_docker_compose(reuse_config=False): header("Dashboard Configuration") if not COMPOSE_FILE.exists(): die(f"docker-compose.yml not found at {COMPOSE_FILE}\n" f" Ensure the routlin-dash directory is at {COMPOSE_FILE.parent}") - content = COMPOSE_FILE.read_text() + if reuse_config: + print("\n Stopping existing container...") + subprocess.run(["docker", "compose", "down"], cwd=COMPOSE_FILE.parent, check=False) + print("\n Starting dashboard container...") + result = subprocess.run( + ["docker", "compose", "up", "-d", "--build"], + cwd=COMPOSE_FILE.parent, check=False + ) + if result.returncode != 0: + die("docker compose up failed. Check the output above.") + print(" Dashboard container started.") + return - existing_key = re.search(r"^\s*- SECRET_KEY=(.+)$", content, re.MULTILINE) - if existing_key and existing_key.group(1).strip(): - print(" Dashboard is already configured.") - if not prompt_yn("Reconfigure? (generates a new SECRET_KEY, invalidates existing sessions)", default="n"): - print() - print(" Starting dashboard container...") - result = subprocess.run( - ["docker", "compose", "up", "-d", "--build"], - cwd=COMPOSE_FILE.parent, check=False - ) - if result.returncode != 0: - die("docker compose up failed. Check the output above.") - print(" Dashboard container started.") - return + content = COMPOSE_FILE.read_text() print(" Generating SECRET_KEY...") secret_key = secrets.token_urlsafe(96) # ~128 chars @@ -455,7 +458,12 @@ def main(): print(" be edited manually.") print() - want_dashboard = prompt_yn("Install the web dashboard?", default="y") + dash_installed = _dash_already_configured() + if dash_installed: + print(" Web dashboard is already installed.") + want_dashboard = prompt_yn("Rebuild?", default="n") + else: + want_dashboard = prompt_yn("Install the web dashboard?", default="y") if not want_dashboard: print() @@ -466,6 +474,13 @@ def main(): print("Done.") return + reuse_config = False + if dash_installed: + reuse_config = prompt_yn( + "Re-use existing configuration? (Keeps SECRET_KEY and SMTP credentials, preserving active sessions and email settings)", + default="y" + ) + # -- Docker ---------------------------------------------------- header("Docker") if pm_ok: @@ -476,7 +491,7 @@ def main(): print(" Docker is already installed.") # -- docker-compose.yml ---------------------------------------- - setup_docker_compose() + setup_docker_compose(reuse_config=reuse_config) create_dotfiles() # -- External access -------------------------------------------