#!/usr/bin/env python

import argparse
import subprocess


SERVER = "michaelgalloy.com"
DIR = "www/.well-known/acme-challenge"


def respond(filename, content):
    with open(filename, "w") as f:
        f.write(content)
    dst = f"{SERVER}:{DIR}"
    cmd = ["scp", filename, dst]
    print(" ".join(cmd))
    subprocess.Popen(cmd, encoding="utf-8")


def main():
    name = "certbot HTTP challenge satisfier"
    parser = argparse.ArgumentParser(description=name)
    parser.add_argument("content", type=str, help="challenge content")
    args = parser.parse_args()

    filename = args.content[0:43]
    respond(filename, args.content)


if __name__ == "__main__":
    main()

    
