agent-zero/prepare.py
Alessandro 7d45b1fb20
Some checks failed
Build And Publish Docker Images / plan (push) Has been cancelled
Build And Publish Docker Images / build (push) Has been cancelled
Preserve .env configuration during startup migration
Migrate and load legacy configuration before preparation writes the root
password. Keep an existing usr/.env authoritative without overwriting
conflicting legacy files or disturbing aliases. Preparation uses stored
dotenv values with the same file-over-environment precedence as UI startup.

Preserve external symlink targets and their replacements, including when
usr/ is itself a symlink. Abort on invalid configuration before creating a
password-only replacement that would hide the saved login credentials.
Cover precedence, aliases, external target replacement, migration failures,
and preparation ordering with regression tests and update the owning docs.

Validation: 80 related tests passed locally; 21 focused tests passed in the
localhost:32081 Docker framework runtime. Full live update/rollback was not
run.
2026-10-14 20:38:20 +02:00

44 lines
1.3 KiB
Python

from helpers import dotenv, migration, runtime, settings
import string
import random
import sys
from helpers.print_style import PrintStyle
def _retire_legacy_collabora_runtime() -> None:
if not any(arg.lower() == "--dockerized=true" for arg in sys.argv):
return
try:
from plugins._office import hooks as office_hooks
result = office_hooks.retire_collabora_web_runtime(force=True)
except Exception as exc:
PrintStyle.warning("Legacy Collabora runtime cleanup failed:", exc)
return
if result.get("errors"):
PrintStyle.warning("Legacy Collabora runtime cleanup reported errors:", result["errors"])
elif result.get("removed"):
PrintStyle.info("Legacy Collabora runtime retired:", result)
PrintStyle.standard("Preparing environment...")
migration.migrate_dotenv()
dotenv.load_dotenv()
try:
_retire_legacy_collabora_runtime()
runtime.initialize()
# generate random root password if not set (for SSH)
root_pass = dotenv.get_dotenv_value(dotenv.KEY_ROOT_PASSWORD)
if not root_pass:
root_pass = "".join(random.choices(string.ascii_letters + string.digits, k=32))
PrintStyle.standard("Changing root password...")
settings.set_root_password(root_pass)
except Exception as e:
PrintStyle.error(f"Error in preload: {e}")