fix(install): a fresh install creates ntfy accounts without prompts (database created first; phone uses the web password)

This commit is contained in:
2026-10-23 23:38:51 +01:00
parent 9bad1bd824
commit 3d0c034394
4 changed files with 97 additions and 16 deletions
+17 -8
View File
@@ -34,12 +34,15 @@ def save_token(output, path, mode=0o444):
return path
def bootstrap_accounts(run, token_path, mode=0o444, log=print):
def bootstrap_accounts(run, token_path, mode=0o444, log=print, publisher_password=None,
reader_password=None):
"""Create the pipeline-publisher and phone-reader accounts on an ntfy server.
``run(args, capture=False, interactive=False)`` executes the ntfy CLI (directly
or through Compose) and returns the completed process. Existing accounts and an
existing token file are preserved on reinstall.
``run(args, capture=False, interactive=False, password=None)`` executes the ntfy
CLI (directly or through Compose) and returns the completed process; a given
password is supplied without a prompt. Without one the CLI asks on the
terminal. Existing accounts and an existing token file are preserved on
reinstall.
"""
token_path = Path(token_path)
if token_path.is_symlink():
@@ -47,14 +50,20 @@ def bootstrap_accounts(run, token_path, mode=0o444, log=print):
if token_path.exists() and token_path.stat().st_size:
log("Keeping existing ntfy publishing token.")
else:
log("Set a password for ntfy's pipeline-publisher account (not a model-provider account).")
run(["user", "add", "--ignore-exists", "pipeline-publisher"], interactive=True)
if publisher_password is None:
log("Set a password for ntfy's pipeline-publisher account (not a model-provider account).")
run(["user", "add", "--ignore-exists", "pipeline-publisher"], interactive=True)
else:
run(["user", "add", "--ignore-exists", "pipeline-publisher"], password=publisher_password)
run(["access", "pipeline-publisher", "pipelines", "write-only"])
result = run(["token", "add", "pipeline-publisher"], capture=True)
save_token(result.stdout + result.stderr, token_path, mode)
# --ignore-exists preserves the phone account's password on reinstall.
log("Set the phone-reader password if this is a new ntfy account; existing accounts are preserved.")
run(["user", "add", "--ignore-exists", "phone-reader"], interactive=True)
if reader_password is None:
log("Set the phone-reader password if this is a new ntfy account; existing accounts are preserved.")
run(["user", "add", "--ignore-exists", "phone-reader"], interactive=True)
else:
run(["user", "add", "--ignore-exists", "phone-reader"], password=reader_password)
run(["access", "phone-reader", "pipelines", "read-only"])