mirror of
https://github.com/chatmail/relay.git
synced 2026-05-20 04:48:06 +00:00
cmdeploy run: don't run if crucial DNS entries are missing
This commit is contained in:
@@ -15,7 +15,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
from termcolor import colored
|
from termcolor import colored
|
||||||
from chatmaild.config import read_config, write_initial_config
|
from chatmaild.config import read_config, write_initial_config
|
||||||
import cmdeploy.dns
|
from cmdeploy.dns import resolve
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -38,8 +38,8 @@ def init_cmd(args, out):
|
|||||||
else:
|
else:
|
||||||
write_initial_config(args.inipath, args.chatmail_domain)
|
write_initial_config(args.inipath, args.chatmail_domain)
|
||||||
out.green(f"created config file for {args.chatmail_domain} in {args.inipath}")
|
out.green(f"created config file for {args.chatmail_domain} in {args.inipath}")
|
||||||
ipaddress, _ = cmdeploy.dns.resolve(args.chatmail_domain)
|
ipaddress = resolve(args.chatmail_domain)
|
||||||
mta_ipadress, _ = cmdeploy.dns.resolve("mta-sts." + args.chatmail_domain)
|
mta_ipadress = resolve("mta-sts." + args.chatmail_domain)
|
||||||
entries = 0
|
entries = 0
|
||||||
to_print = ["Now you should add %dnsentry% at your DNS provider:\n"]
|
to_print = ["Now you should add %dnsentry% at your DNS provider:\n"]
|
||||||
if not ipaddress:
|
if not ipaddress:
|
||||||
@@ -47,7 +47,9 @@ def init_cmd(args, out):
|
|||||||
to_print.append(f"\tA\t{args.chatmail_domain}\t\t<your server's IPv4 address>")
|
to_print.append(f"\tA\t{args.chatmail_domain}\t\t<your server's IPv4 address>")
|
||||||
if not mta_ipadress:
|
if not mta_ipadress:
|
||||||
entries += 1
|
entries += 1
|
||||||
to_print.append(f"\tCNAME\tmta-sts.{args.chatmail_domain}\t{args.chatmail_domain}.")
|
to_print.append(
|
||||||
|
f"\tCNAME\tmta-sts.{args.chatmail_domain}\t{args.chatmail_domain}."
|
||||||
|
)
|
||||||
if entries == 1:
|
if entries == 1:
|
||||||
singular = "this entry"
|
singular = "this entry"
|
||||||
elif entries == 2:
|
elif entries == 2:
|
||||||
@@ -57,6 +59,7 @@ def init_cmd(args, out):
|
|||||||
to_print[0] = to_print[0].replace("%dnsentry%", singular)
|
to_print[0] = to_print[0].replace("%dnsentry%", singular)
|
||||||
for line in to_print:
|
for line in to_print:
|
||||||
print(line)
|
print(line)
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
def run_cmd_options(parser):
|
def run_cmd_options(parser):
|
||||||
@@ -76,6 +79,12 @@ def run_cmd(args, out):
|
|||||||
deploy_path = importlib.resources.files(__package__).joinpath("deploy.py").resolve()
|
deploy_path = importlib.resources.files(__package__).joinpath("deploy.py").resolve()
|
||||||
pyinf = "pyinfra --dry" if args.dry_run else "pyinfra"
|
pyinf = "pyinfra --dry" if args.dry_run else "pyinfra"
|
||||||
cmd = f"{pyinf} --ssh-user root {args.config.mail_domain} {deploy_path}"
|
cmd = f"{pyinf} --ssh-user root {args.config.mail_domain} {deploy_path}"
|
||||||
|
|
||||||
|
mail_domain = args.config.mail_domain
|
||||||
|
if not resolve(mail_domain) or not resolve(f"mta-sts.{mail_domain}"):
|
||||||
|
out.red("DNS entries missing. Show instructions with:\n")
|
||||||
|
print(f"\tcmdeploy init {mail_domain}\n")
|
||||||
|
sys.exit(1)
|
||||||
out.check_call(cmd, env=env)
|
out.check_call(cmd, env=env)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,15 +7,15 @@ dns_types = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def resolve(domain: str) -> (str, str):
|
def resolve(domain: str) -> str:
|
||||||
result, typ = get("A", domain), "A"
|
result = get("A", domain)
|
||||||
if not result:
|
if not result:
|
||||||
result = get("CNAME", domain)
|
result = get("CNAME", domain)
|
||||||
if result:
|
if result:
|
||||||
result, typ = get("A", result[:-1]), "A"
|
result = get("A", result[:-1])
|
||||||
if not result:
|
if not result:
|
||||||
result, typ = get("AAAA", domain), "AAAA"
|
result = get("AAAA", domain)
|
||||||
return result, typ
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get(typ: str, domain: str) -> str:
|
def get(typ: str, domain: str) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user