fedora (6576B)
1#!/usr/bin/env python3 2# 3# Fedora VM image 4# 5# Copyright 2019 Red Hat Inc. 6# 7# Authors: 8# Gerd Hoffmann <kraxel@redhat.com> 9# 10# This code is licensed under the GPL version 2 or later. See 11# the COPYING file in the top-level directory. 12# 13 14import os 15import re 16import sys 17import time 18import socket 19import subprocess 20import basevm 21 22class FedoraVM(basevm.BaseVM): 23 name = "fedora" 24 arch = "x86_64" 25 26 base = "https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/30/" 27 link = base + "Server/x86_64/iso/Fedora-Server-netinst-x86_64-30-1.2.iso" 28 repo = base + "Server/x86_64/os/" 29 full = base + "Everything/x86_64/os/" 30 csum = "5e4eac4566d8c572bfb3bcf54b7d6c82006ec3c6c882a2c9235c6d3494d7b100" 31 size = "20G" 32 pkgs = [ 33 # tools 34 'git-core', 35 'gcc', 'binutils', 'make', 'ninja-build', 36 37 # perl 38 'perl-Test-Harness', 39 40 # libs: usb 41 '"pkgconfig(libusb-1.0)"', 42 '"pkgconfig(libusbredirparser-0.5)"', 43 44 # libs: crypto 45 '"pkgconfig(gnutls)"', 46 47 # libs: ui 48 '"pkgconfig(sdl2)"', 49 '"pkgconfig(gtk+-3.0)"', 50 '"pkgconfig(ncursesw)"', 51 52 # libs: audio 53 '"pkgconfig(libpulse)"', 54 '"pkgconfig(alsa)"', 55 56 # libs: migration 57 '"pkgconfig(libzstd)"', 58] 59 60 BUILD_SCRIPT = """ 61 set -e; 62 rm -rf /home/qemu/qemu-test.* 63 cd $(mktemp -d /home/qemu/qemu-test.XXXXXX); 64 mkdir src build; cd src; 65 tar -xf /dev/vdb; 66 cd ../build 67 ../src/configure --python=python3 {configure_opts}; 68 gmake --output-sync -j{jobs} {target} {verbose}; 69 """ 70 71 def build_image(self, img): 72 self.print_step("Downloading install iso") 73 cimg = self._download_with_cache(self.link, sha256sum=self.csum) 74 img_tmp = img + ".tmp" 75 iso = img + ".install.iso" 76 77 self.print_step("Preparing iso and disk image") 78 subprocess.check_call(["cp", "-f", cimg, iso]) 79 self.exec_qemu_img("create", "-f", "qcow2", img_tmp, self.size) 80 self.print_step("Booting installer") 81 self.boot(img_tmp, extra_args = [ 82 "-bios", "pc-bios/bios-256k.bin", 83 "-machine", "graphics=off", 84 "-device", "VGA", 85 "-cdrom", iso 86 ]) 87 self.console_init(300) 88 self.console_wait("installation process.") 89 time.sleep(0.3) 90 self.console_send("\t") 91 time.sleep(0.3) 92 self.console_send(" console=ttyS0") 93 proxy = os.environ.get("http_proxy") 94 if not proxy is None: 95 self.console_send(" proxy=%s" % proxy) 96 self.console_send(" inst.proxy=%s" % proxy) 97 self.console_send(" inst.repo=%s" % self.repo) 98 self.console_send("\n") 99 100 self.console_wait_send("2) Use text mode", "2\n") 101 102 self.console_wait_send("5) [!] Installation Dest", "5\n") 103 self.console_wait_send("1) [x]", "c\n") 104 self.console_wait_send("2) [ ] Use All Space", "2\n") 105 self.console_wait_send("2) [x] Use All Space", "c\n") 106 self.console_wait_send("1) [ ] Standard Part", "1\n") 107 self.console_wait_send("1) [x] Standard Part", "c\n") 108 109 self.console_wait_send("7) [!] Root password", "7\n") 110 self.console_wait("Password:") 111 self.console_send("%s\n" % self._config["root_pass"]) 112 self.console_wait("Password (confirm):") 113 self.console_send("%s\n" % self._config["root_pass"]) 114 115 self.console_wait_send("8) [ ] User creation", "8\n") 116 self.console_wait_send("1) [ ] Create user", "1\n") 117 self.console_wait_send("3) User name", "3\n") 118 self.console_wait_send("ENTER:", "%s\n" % self._config["guest_user"]) 119 self.console_wait_send("4) [ ] Use password", "4\n") 120 self.console_wait_send("5) Password", "5\n") 121 self.console_wait("Password:") 122 self.console_send("%s\n" % self._config["guest_pass"]) 123 self.console_wait("Password (confirm):") 124 self.console_send("%s\n" % self._config["guest_pass"]) 125 self.console_wait_send("7) Groups", "c\n") 126 127 while True: 128 good = self.console_wait("3) [x] Installation", 129 "3) [!] Installation") 130 self.console_send("r\n") 131 if good: 132 break 133 time.sleep(10) 134 135 while True: 136 good = self.console_wait("4) [x] Software", 137 "4) [!] Software") 138 self.console_send("r\n") 139 if good: 140 break 141 time.sleep(10) 142 self.console_send("r\n" % self._config["guest_pass"]) 143 144 self.console_wait_send("'b' to begin install", "b\n") 145 146 self.print_step("Installation started now, this will take a while") 147 148 self.console_wait_send("Installation complete", "\n") 149 self.print_step("Installation finished, rebooting") 150 151 # setup qemu user 152 prompt = " ~]$" 153 self.console_ssh_init(prompt, self._config["guest_user"], 154 self._config["guest_pass"]) 155 self.console_wait_send(prompt, "exit\n") 156 157 # setup root user 158 prompt = " ~]#" 159 self.console_ssh_init(prompt, "root", self._config["root_pass"]) 160 self.console_sshd_config(prompt) 161 162 # setup virtio-blk #1 (tarfile) 163 self.console_wait(prompt) 164 self.console_send("echo 'KERNEL==\"vdb\" MODE=\"666\"' >> %s\n" % 165 "/etc/udev/rules.d/99-qemu.rules") 166 167 self.print_step("Configuration finished, rebooting") 168 self.console_wait_send(prompt, "reboot\n") 169 self.console_wait("login:") 170 self.wait_ssh() 171 172 self.print_step("Installing packages") 173 self.ssh_root_check("rm -vf /etc/yum.repos.d/fedora*.repo\n") 174 self.ssh_root_check("echo '[fedora]' >> /etc/yum.repos.d/qemu.repo\n") 175 self.ssh_root_check("echo 'baseurl=%s' >> /etc/yum.repos.d/qemu.repo\n" % self.full) 176 self.ssh_root_check("echo 'gpgcheck=0' >> /etc/yum.repos.d/qemu.repo\n") 177 self.ssh_root_check("dnf install -y %s\n" % " ".join(self.pkgs)) 178 179 # shutdown 180 self.ssh_root(self.poweroff) 181 self.console_wait("sleep state S5") 182 self.wait() 183 184 if os.path.exists(img): 185 os.remove(img) 186 os.rename(img_tmp, img) 187 os.remove(iso) 188 self.print_step("All done") 189 190if __name__ == "__main__": 191 sys.exit(basevm.main(FedoraVM))