#!/usr/bin/env python3
#
# Fedora VM image
#
# Copyright 2019 Red Hat Inc.
#
# Authors:
#  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 FedoraVM(basevm.BaseVM):
    name = "fedora"
    arch = "x86_64"

    base = "https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/30/"
    link = base + "Server/x86_64/iso/Fedora-Server-netinst-x86_64-30-1.2.iso"
    repo = base + "Server/x86_64/os/"
    full = base + "Everything/x86_64/os/"
    csum = "5e4eac4566d8c572bfb3bcf54b7d6c82006ec3c6c882a2c9235c6d3494d7b100"
    size = "20G"
    pkgs = [
        # tools
        'git-core',
        'gcc', 'binutils', 'make', 'ninja-build',

        # perl
        'perl',

        # libs: usb
        '"pkgconfig(libusb-1.0)"',
        '"pkgconfig(libusbredirparser-0.5)"',

        # libs: crypto
        '"pkgconfig(gnutls)"',

        # libs: ui
        '"pkgconfig(sdl2)"',
        '"pkgconfig(gtk+-3.0)"',
        '"pkgconfig(ncursesw)"',

        # libs: audio
        '"pkgconfig(libpulse)"',
        '"pkgconfig(alsa)"',

        # libs: migration
        '"pkgconfig(libzstd)"',
]

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

    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"

        self.print_step("Preparing iso and disk image")
        subprocess.check_call(["cp", "-f", cimg, iso])
        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(300)
        self.console_wait("installation process.")
        time.sleep(0.3)
        self.console_send("\t")
        time.sleep(0.3)
        self.console_send(" console=ttyS0")
        proxy = os.environ.get("http_proxy")
        if not proxy is None:
            self.console_send(" proxy=%s" % proxy)
            self.console_send(" inst.proxy=%s" % proxy)
        self.console_send(" inst.repo=%s" % self.repo)
        self.console_send("\n")

        self.console_wait_send("2) Use text mode",         "2\n")

        self.console_wait_send("5) [!] Installation Dest", "5\n")
        self.console_wait_send("1) [x]",                   "c\n")
        self.console_wait_send("2) [ ] Use All Space",     "2\n")
        self.console_wait_send("2) [x] Use All Space",     "c\n")
        self.console_wait_send("1) [ ] Standard Part",     "1\n")
        self.console_wait_send("1) [x] Standard Part",     "c\n")

        self.console_wait_send("7) [!] Root password",     "7\n")
        self.console_wait("Password:")
        self.console_send("%s\n" % self._config["root_pass"])
        self.console_wait("Password (confirm):")
        self.console_send("%s\n" % self._config["root_pass"])

        self.console_wait_send("8) [ ] User creation",     "8\n")
        self.console_wait_send("1) [ ] Create user",       "1\n")
        self.console_wait_send("3) User name",             "3\n")
        self.console_wait_send("ENTER:", "%s\n" % self._config["guest_user"])
        self.console_wait_send("4) [ ] Use password",      "4\n")
        self.console_wait_send("5) Password",              "5\n")
        self.console_wait("Password:")
        self.console_send("%s\n" % self._config["guest_pass"])
        self.console_wait("Password (confirm):")
        self.console_send("%s\n" % self._config["guest_pass"])
        self.console_wait_send("7) Groups",                "c\n")

        while True:
            good = self.console_wait("3) [x] Installation",
                                     "3) [!] Installation")
            self.console_send("r\n")
            if good:
                break
            time.sleep(10)

        while True:
            good = self.console_wait("4) [x] Software",
                                     "4) [!] Software")
            self.console_send("r\n")
            if good:
                break
            time.sleep(10)
            self.console_send("r\n" % self._config["guest_pass"])

        self.console_wait_send("'b' to begin install",     "b\n")

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

        self.console_wait_send("Installation complete",    "\n")
        self.print_step("Installation finished, rebooting")

        # 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 = " ~]#"
        self.console_ssh_init(prompt, "root", self._config["root_pass"])
        self.console_sshd_config(prompt)

        # setup virtio-blk #1 (tarfile)
        self.console_wait(prompt)
        self.console_send("echo 'KERNEL==\"vdb\" MODE=\"666\"' >> %s\n" %
                          "/etc/udev/rules.d/99-qemu.rules")

        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("rm -vf /etc/yum.repos.d/fedora*.repo\n")
        self.ssh_root_check("echo '[fedora]' >> /etc/yum.repos.d/qemu.repo\n")
        self.ssh_root_check("echo 'baseurl=%s' >> /etc/yum.repos.d/qemu.repo\n" % self.full)
        self.ssh_root_check("echo 'gpgcheck=0' >> /etc/yum.repos.d/qemu.repo\n")
        self.ssh_root_check("dnf install -y %s\n" % " ".join(self.pkgs))

        # shutdown
        self.ssh_root(self.poweroff)
        self.console_wait("sleep state S5")
        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(FedoraVM))
