#!/usr/bin/env python3
#
# FreeBSD 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 re
import sys
import time
import socket
import subprocess
import basevm

class FreeBSDVM(basevm.BaseVM):
    name = "freebsd"
    arch = "x86_64"

    link = "https://download.freebsd.org/ftp/releases/ISO-IMAGES/12.1/FreeBSD-12.1-RELEASE-amd64-disc1.iso.xz"
    csum = "7394c3f60a1e236e7bd3a05809cf43ae39a3b8e5d42d782004cf2f26b1cfcd88"
    size = "20G"
    pkgs = [
        # build tools
        "git",
        "pkgconf",
        "bzip2",
        "python37",
        "py37-setuptools",

        # gnu tools
        "bash",
        "gmake",
        "gsed",
        "gettext",

        # libs: crypto
        "gnutls",

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

        # libs: ui
        "sdl2",
        "gtk3",
        "libxkbcommon",

        # libs: opengl
        "libepoxy",
        "mesa-libs",

        # libs: migration
        "zstd",
    ]

    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/vtbd1;
        cd ../build
        ../src/configure --python=python3.7 {configure_opts};
        gmake --output-sync -j{jobs} {target} {verbose};
    """

    def console_boot_serial(self):
        self.console_wait_send("Autoboot", "3")
        self.console_wait_send("OK", "set console=comconsole\n")
        self.console_wait_send("OK", "boot\n")

    def build_image(self, img):
        self.print_step("Downloading install iso")
        cimg = self._download_with_cache(self.link, sha256sum=self.csum)
        img_tmp = img + ".tmp"
        iso = img + ".install.iso"
        iso_xz = iso + ".xz"

        self.print_step("Preparing iso and disk image")
        subprocess.check_call(["cp", "-f", cimg, iso_xz])
        subprocess.check_call(["xz", "-dvf", iso_xz])
        self.exec_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",
            "-device", "VGA",
            "-cdrom", iso
        ])
        self.console_init()
        self.console_boot_serial()
        self.console_wait_send("Console type",          "xterm\n")

        # pre-install configuration
        self.console_wait_send("Welcome",               "\n")
        self.console_wait_send("Keymap Selection",      "\n")
        self.console_wait_send("Set Hostname",          "freebsd\n")
        self.console_wait_send("Distribution Select",   "\n")
        self.console_wait_send("Partitioning",          "\n")
        self.console_wait_send("Partition",             "\n")
        self.console_wait_send("Scheme",                "\n")
        self.console_wait_send("Editor",                "f")
        self.console_wait_send("Confirmation",          "c")

        self.print_step("Installation started now, this will take a while")

        # post-install configuration
        self.console_wait("New Password:")
        self.console_send("%s\n" % self._config["root_pass"])
        self.console_wait("Retype New Password:")
        self.console_send("%s\n" % self._config["root_pass"])

        self.console_wait_send("Network Configuration", "\n")
        self.console_wait_send("IPv4",                  "y")
        self.console_wait_send("DHCP",                  "y")
        self.console_wait_send("IPv6",                  "n")
        self.console_wait_send("Resolver",              "\n")

        self.console_wait_send("Time Zone Selector",    "a\n")
        self.console_wait_send("Confirmation",          "y")
        self.console_wait_send("Time & Date",           "\n")
        self.console_wait_send("Time & Date",           "\n")

        self.console_wait_send("System Configuration",  "\n")
        self.console_wait_send("System Hardening",      "\n")

        # qemu user
        self.console_wait_send("Add User Accounts", "y")
        self.console_wait("Username")
        self.console_send("%s\n" % self._config["guest_user"])
        self.console_wait("Full name")
        self.console_send("%s\n" % self._config["guest_user"])
        self.console_wait_send("Uid",                   "\n")
        self.console_wait_send("Login group",           "\n")
        self.console_wait_send("Login group",           "\n")
        self.console_wait_send("Login class",           "\n")
        self.console_wait_send("Shell",                 "\n")
        self.console_wait_send("Home directory",        "\n")
        self.console_wait_send("Home directory perm",   "\n")
        self.console_wait_send("Use password",          "\n")
        self.console_wait_send("Use an empty password", "\n")
        self.console_wait_send("Use a random password", "\n")
        self.console_wait("Enter password:")
        self.console_send("%s\n" % self._config["guest_pass"])
        self.console_wait("Enter password again:")
        self.console_send("%s\n" % self._config["guest_pass"])
        self.console_wait_send("Lock out",              "\n")
        self.console_wait_send("OK",                    "yes\n")
        self.console_wait_send("Add another user",      "no\n")

        self.console_wait_send("Final Configuration",   "\n")
        self.console_wait_send("Manual Configuration",  "\n")
        self.console_wait_send("Complete",              "\n")

        self.print_step("Installation finished, rebooting")
        self.console_boot_serial()

        # setup qemu user
        prompt = "$"
        self.console_ssh_init(prompt, self._config["guest_user"], self._config["guest_pass"])
        self.console_wait_send(prompt, "exit\n")

        # setup root user
        prompt = "root@freebsd:~ #"
        self.console_ssh_init(prompt, "root", self._config["root_pass"])
        self.console_sshd_config(prompt)

        # setup serial console
        self.console_wait(prompt)
        self.console_send("echo 'console=comconsole' >> /boot/loader.conf\n")

        # setup boot delay
        self.console_wait(prompt)
        self.console_send("echo 'autoboot_delay=1' >> /boot/loader.conf\n")

        # setup virtio-blk #1 (tarfile)
        self.console_wait(prompt)
        self.console_send("echo 'chmod 666 /dev/vtbd1' >> /etc/rc.local\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("pkg install -y %s\n" % " ".join(self.pkgs))

        # shutdown
        self.ssh_root(self.poweroff)
        self.console_wait("Uptime:")
        self.wait()

        if os.path.exists(img):
            os.remove(img)
        os.rename(img_tmp, img)
        os.remove(iso)
        self.print_step("All done")

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