From 4c0e81224f809a5aa0ab1988fd5af133c0395df7 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sat, 13 Apr 2019 10:03:43 +0200 Subject: [PATCH] Add the in-progress setup wizard --- setup_wizard/Dockerfile | 5 +++ setup_wizard/requirements.txt | 3 ++ setup_wizard/wizard.py | 66 +++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 setup_wizard/Dockerfile create mode 100644 setup_wizard/requirements.txt create mode 100644 setup_wizard/wizard.py diff --git a/setup_wizard/Dockerfile b/setup_wizard/Dockerfile new file mode 100644 index 0000000..4890f07 --- /dev/null +++ b/setup_wizard/Dockerfile @@ -0,0 +1,5 @@ +FROM python:3 +WORKDIR /app +ADD . /app +RUN pip install -r requirements.txt +CMD ["python", "wizard.py"] diff --git a/setup_wizard/requirements.txt b/setup_wizard/requirements.txt new file mode 100644 index 0000000..9482032 --- /dev/null +++ b/setup_wizard/requirements.txt @@ -0,0 +1,3 @@ +prompt_toolkit +bcrypt +markdown diff --git a/setup_wizard/wizard.py b/setup_wizard/wizard.py new file mode 100644 index 0000000..10808e7 --- /dev/null +++ b/setup_wizard/wizard.py @@ -0,0 +1,66 @@ +"""Basic wizard for setting up microblog.pub configuration files.""" +import os +import binascii +from pathlib import Path + +import bcrypt +from prompt_toolkit import prompt +from markdown import markdown + + +def main(): + print("Welcome to microblog.pub setup wizard\n") + + dat = {} + print("Your identity will be @{username}@{domain}") + dat["domain"] = prompt("domain: ") + dat["username"] = prompt("username: ") + dat["password"] = bcrypt.hashpw( + prompt("password: ", is_password=True).encode(), bcrypt.gensalt() + ).decode() + dat["name"] = prompt("name (e.g. John Doe): ") + dat["summary"] = markdown( + prompt( + "summary (short description, in markdown, press [ESC] then [ENTER] to submit):\n", + multiline=True, + ) + ) + dat["https"] = True + proto = "https" + yn = "" + while yn not in ["y", "n"]: + yn = prompt("will the site be served via https? (y/n): ", default="y").lower() + if yn == "n": + dat["https"] = False + proto = "http" + + dat["icon_url"] = prompt( + "icon URL: ", default=f'{proto}://{dat["domain"]}/static/nopic.png' + ) + + out = "" + for k, v in dat.items(): + out += f"{k}: {v!r}\n" + print(out) + print() + + env_file = { + "WEB_PORT": 5005, + "CONFIG_DIR": "./config", + "DATA_DIR": "./data", + "POUSSETACHES_AUTH_KEY": binascii.hexlify(os.urandom(32)).decode(), + "COMPOSE_PROJECT_NAME": Path.cwd().name.replace(".", ""), + } + + out2 = "" + for k, v in env_file.items(): + out2 += f"{k}={v}\n" + + print(out2) + + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + pass