2019-04-13 03:03:43 -05:00
|
|
|
"""Basic wizard for setting up microblog.pub configuration files."""
|
|
|
|
import binascii
|
2019-04-22 02:58:11 -05:00
|
|
|
import os
|
|
|
|
import sys
|
2019-04-13 03:03:43 -05:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import bcrypt
|
|
|
|
from markdown import markdown
|
2019-04-22 02:58:11 -05:00
|
|
|
from prompt_toolkit import prompt
|
2019-04-13 03:03:43 -05:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
print("Welcome to microblog.pub setup wizard\n")
|
|
|
|
|
2019-04-22 03:52:32 -05:00
|
|
|
config_file = Path("/app/out/config/me.yml")
|
|
|
|
env_file = Path("/app/out/.env")
|
|
|
|
|
|
|
|
if config_file.exists() or env_file.exists():
|
|
|
|
# Spit out the relative path for the "config artifacts"
|
|
|
|
config_file = "config/me.yml"
|
|
|
|
env_file = ".env"
|
2019-04-22 04:06:54 -05:00
|
|
|
print(
|
|
|
|
f"Existing setup detected, please delete {config_file} and/or {env_file} before restarting the wizard"
|
|
|
|
)
|
2019-04-22 03:52:32 -05:00
|
|
|
sys.exit(2)
|
|
|
|
|
2019-04-13 03:03:43 -05:00
|
|
|
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"
|
|
|
|
|
2019-04-22 03:52:32 -05:00
|
|
|
with config_file.open("w") as f:
|
|
|
|
f.write(out)
|
|
|
|
|
|
|
|
env = {
|
2019-04-13 03:03:43 -05:00
|
|
|
"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 = ""
|
2019-04-22 03:52:32 -05:00
|
|
|
for k, v in env.items():
|
2019-04-13 03:03:43 -05:00
|
|
|
out2 += f"{k}={v}\n"
|
|
|
|
|
2019-04-22 03:52:32 -05:00
|
|
|
with env_file.open("w") as f:
|
|
|
|
f.write(out2)
|
|
|
|
|
|
|
|
print("Done")
|
|
|
|
sys.exit(0)
|
2019-04-13 03:03:43 -05:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
try:
|
|
|
|
main()
|
|
|
|
except KeyboardInterrupt:
|
2019-04-22 02:58:11 -05:00
|
|
|
print("Aborted")
|
|
|
|
sys.exit(1)
|