#!/usr/bin/env python
#
# NetBSD VM image
#
# Copyright 2017-2019 Red Hat Inc.
#
# Authors:
#  Fam Zheng <famz@redhat.com>
#  Gerd Hoffmann <kraxel@redhat.com>
#
# This code is licensed under the GPL version 2 or later.  See
# the COPYING file in the top-level directory.
#

import os
import sys
import time
import subprocess
import basevm

class NetBSDVM(basevm.BaseVM):
    name = "netbsd"
    arch = "x86_64"

    link = "https://cdn.netbsd.org/pub/NetBSD/NetBSD-8.1/images/NetBSD-8.1-amd64.iso"
    csum = "718f275b7e0879599bdac95630c5e3f2184700032fdb6cdebf3bdd63687898c48ff3f08f57b89f4437a86cdd8ea07c01a39d432dbb37e1e4b008f4985f98da3f"
    size = "20G"
    pkgs = [
        # tools
        "git-base",
        "pkgconf",
        "xz",
        "python37",

        # gnu tools
        "bash",
        "gmake",
        "gsed",
        "flex", "bison",

        # libs: crypto
        "gnutls",

        # libs: images
        "jpeg",
        "png",

	# libs: ui
        "SDL2",
        "gtk3+",
        "libxkbcommon",
    ]

    BUILD_SCRIPT = """
        set -e;
        rm -rf /home/qemu/qemu-test.*
        cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
        mkdir src build; cd src;
        tar -xf /dev/rld1a;
        cd ../build
        ../src/configure --python=python3.7 --disable-opengl {configure_opts};
        gmake --output-sync -j{jobs} {target} {verbose};
    """
    poweroff = "/sbin/poweroff"

    # Workaround for NetBSD + IPv6 + slirp issues.
    # NetBSD seems to ignore the ICMPv6 Destination Unreachable
    # messages generated by slirp.  When the host has no IPv6
    # connectivity, this causes every connection to ftp.NetBSD.org
    # take more than a minute to be established.
    ipv6 = False

    def build_image(self, img):
        cimg = self._download_with_cache(self.link, sha512sum=self.csum)
        img_tmp = img + ".tmp"
        iso = img + ".install.iso"

        self.print_step("Preparing iso and disk image")
        subprocess.check_call(["ln", "-f", cimg, iso])
        subprocess.check_call(["qemu-img", "create", "-f", "qcow2",
                               img_tmp, self.size])

        self.print_step("Booting installer")
        self.boot(img_tmp, extra_args = [
            "-bios", "pc-bios/bios-256k.bin",
            "-machine", "graphics=off",
            "-cdrom", iso
        ])
        self.console_init()
        self.console_wait("Primary Bootstrap")

        # serial console boot menu output doesn't work for some
        # reason, so we have to fly blind ...
        for char in list("5consdev com0\n"):
            time.sleep(0.2)
            self.console_send(char)
            self.console_consume()
        self.console_wait_send("> ", "boot\n")

        self.console_wait_send("Terminal type",            "xterm\n")
        self.console_wait_send("a: Installation messages", "a\n")
        self.console_wait_send("b: US-English",            "b\n")
        self.console_wait_send("a: Install NetBSD",        "a\n")
        self.console_wait("Shall we continue?")
        self.console_wait_send("b: Yes",                   "b\n")

        self.console_wait_send("a: ld0",                   "a\n")
        self.console_wait_send("a: This is the correct",   "a\n")
        self.console_wait_send("b: Use the entire disk",   "b\n")
        self.console_wait("NetBSD bootcode")
        self.console_wait_send("a: Yes",                   "a\n")
        self.console_wait_send("b: Use existing part",     "b\n")
        self.console_wait_send("x: Partition sizes ok",    "x\n")
        self.console_wait_send("for your NetBSD disk",     "\n")
        self.console_wait("Shall we continue?")
        self.console_wait_send("b: Yes",                   "b\n")

        self.console_wait_send("b: Use serial port com0",  "b\n")
        self.console_wait_send("f: Set serial baud rate",  "f\n")
        self.console_wait_send("a: 9600",                  "a\n")
        self.console_wait_send("x: Exit",                  "x\n")

        self.console_wait_send("a: Full installation",     "a\n")
        self.console_wait_send("a: CD-ROM",                "a\n")

        self.print_step("Installation started now, this will take a while")
        self.console_wait_send("Hit enter to continue",    "\n")

        self.console_wait_send("d: Change root password",  "d\n")
        self.console_wait_send("a: Yes",                   "a\n")
        self.console_wait("New password:")
        self.console_send("%s\n" % self.ROOT_PASS)
        self.console_wait("New password:")
        self.console_send("%s\n" % self.ROOT_PASS)
        self.console_wait("Retype new password:")
        self.console_send("%s\n" % self.ROOT_PASS)

        self.console_wait_send("o: Add a user",            "o\n")
        self.console_wait("username")
        self.console_send("%s\n" % self.GUEST_USER)
        self.console_wait("to group wheel")
        self.console_wait_send("a: Yes",                   "a\n")
        self.console_wait_send("a: /bin/sh",               "a\n")
        self.console_wait("New password:")
        self.console_send("%s\n" % self.GUEST_PASS)
        self.console_wait("New password:")
        self.console_send("%s\n" % self.GUEST_PASS)
        self.console_wait("Retype new password:")
        self.console_send("%s\n" % self.GUEST_PASS)

        self.console_wait_send("a: Configure network",     "a\n")
        self.console_wait_send("a: vioif0",                "a\n")
        self.console_wait_send("Network media type",       "\n")
        self.console_wait("autoconfiguration")
        self.console_wait_send("a: Yes",                   "a\n")
        self.console_wait_send("DNS domain",               "localnet\n")
        self.console_wait("Are they OK?")
        self.console_wait_send("a: Yes",                   "a\n")
        self.console_wait("installed in /etc")
        self.console_wait_send("a: Yes",                   "a\n")

        self.console_wait_send("e: Enable install",        "e\n")
        proxy = os.environ.get("http_proxy")
        if not proxy is None:
            self.console_wait_send("f: Proxy",             "f\n")
            self.console_wait("Proxy")
            self.console_send("%s\n" % proxy)
        self.console_wait_send("x: Install pkgin",         "x\n")
        self.console_init(1200)
        self.console_wait_send("Hit enter to continue", "\n")
        self.console_init()

        self.console_wait_send("g: Enable sshd",           "g\n")
        self.console_wait_send("x: Finished conf",         "x\n")
        self.console_wait_send("Hit enter to continue",    "\n")

        self.print_step("Installation finished, rebooting")
        self.console_wait_send("d: Reboot the computer",   "d\n")

        # setup qemu user
        prompt = "localhost$"
        self.console_ssh_init(prompt, self.GUEST_USER, self.GUEST_PASS)
        self.console_wait_send(prompt, "exit\n")

        # setup root user
        prompt = "localhost#"
        self.console_ssh_init(prompt, "root", self.ROOT_PASS)
        self.console_sshd_config(prompt)

        # setup virtio-blk #1 (tarfile)
        self.console_wait(prompt)
        self.console_send("echo 'chmod 666 /dev/rld1a' >> /etc/rc.local\n")

        # turn off mprotect (conflicts with tcg)
        self.console_wait(prompt)
        self.console_send("echo security.pax.mprotect.enabled=0 >> /etc/sysctl.conf\n")

        self.print_step("Configuration finished, rebooting")
        self.console_wait_send(prompt, "reboot\n")
        self.console_wait("login:")
        self.wait_ssh()

        self.print_step("Installing packages")
        self.ssh_root_check("pkgin update\n")
        self.ssh_root_check("pkgin -y install %s\n" % " ".join(self.pkgs))

        # shutdown
        self.ssh_root(self.poweroff)
        self.console_wait("entering state S5")
        self.wait()

        os.rename(img_tmp, img)
        os.remove(iso)
        self.print_step("All done")

if __name__ == "__main__":
    sys.exit(basevm.main(NetBSDVM))
