45 lines
1.5 KiB
Python
Executable File
45 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Drive the historical bongo-config install prompt on a disposable root."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import shlex
|
|
import sys
|
|
|
|
|
|
if os.environ.get("BONGO_ALLOW_LEGACY_INSTALL") != "1":
|
|
raise SystemExit("set BONGO_ALLOW_LEGACY_INSTALL=1 for a disposable root")
|
|
password = os.environ.get("BONGO_TEST_PASSWORD", "")
|
|
if len(password) < 12:
|
|
raise SystemExit("set a disposable BONGO_TEST_PASSWORD (12+ characters)")
|
|
|
|
try:
|
|
import pexpect
|
|
except ImportError as error:
|
|
raise SystemExit("legacy-config-install.py requires pexpect") from error
|
|
|
|
command = shlex.split(os.environ.get(
|
|
"BONGO_CONFIG_INSTALL", "/usr/bin/bongo-config install"))
|
|
child = pexpect.spawn(
|
|
command[0], command[1:], encoding="utf-8", timeout=180,
|
|
env=os.environ.copy())
|
|
child.logfile = sys.stdout
|
|
child.expect("IP address to run on")
|
|
child.sendline(os.environ.get("BONGO_TEST_BIND", "127.0.0.1"))
|
|
child.expect("DNS name to use as main hostname")
|
|
child.sendline(os.environ.get("BONGO_TEST_HOSTNAME", "mail.bongo.test"))
|
|
child.expect("Mail Domains")
|
|
child.sendline(os.environ.get("BONGO_TEST_DOMAIN", "bongo.test"))
|
|
child.expect("Mail Domains")
|
|
child.sendline("")
|
|
child.expect("Initial password for the admin user")
|
|
child.sendline(password)
|
|
child.expect("Confirm the admin password")
|
|
child.sendline(password)
|
|
child.expect(pexpect.EOF)
|
|
child.close()
|
|
if child.signalstatus is not None:
|
|
raise SystemExit(128 + child.signalstatus)
|
|
raise SystemExit(child.exitstatus if child.exitstatus is not None else 1)
|