1#!/usr/bin/env python3 2# 3# Haiku VM image 4# 5# Copyright 2020-2022 Haiku, Inc. 6# 7# Authors: 8# Alexander von Gluck IV <kallisti5@unixzen.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 22VAGRANT_KEY_FILE = os.path.join(os.path.dirname(__file__), 23 "..", "keys", "vagrant") 24 25VAGRANT_PUB_KEY_FILE = os.path.join(os.path.dirname(__file__), 26 "..", "keys", "vagrant.pub") 27 28HAIKU_CONFIG = { 29 'cpu' : "max", 30 'machine' : 'pc', 31 'guest_user' : "vagrant", 32 'guest_pass' : "", 33 'root_user' : "vagrant", 34 'root_pass' : "", 35 'ssh_key_file' : VAGRANT_KEY_FILE, 36 'ssh_pub_key_file': VAGRANT_PUB_KEY_FILE, 37 'memory' : "4G", 38 'extra_args' : [], 39 'qemu_args' : "-device VGA", 40 'dns' : "", 41 'ssh_port' : 0, 42 'install_cmds' : "", 43 'boot_dev_type' : "block", 44 'ssh_timeout' : 1, 45} 46 47class HaikuVM(basevm.BaseVM): 48 name = "haiku" 49 arch = "x86_64" 50 51 link = "https://app.vagrantup.com/haiku-os/boxes/r1beta3-x86_64/versions/20220216/providers/libvirt.box" 52 csum = "e67d4aacbcc687013d5cc91990ddd86cc5d70a5d28432ae2691944f8ce5d5041" 53 54 poweroff = "shutdown" 55 56 requirements = [ 57 "devel:libbz2", 58 "devel:libcapstone", 59 "devel:libcurl", 60 "devel:libfdt", 61 "devel:libgcrypt", 62 "devel:libgl", 63 "devel:libglib_2.0", 64 "devel:libgnutls", 65 "devel:libgpg_error", 66 "devel:libintl", 67 "devel:libjpeg", 68 "devel:liblzo2", 69 "devel:libncursesw", 70 "devel:libnettle", 71 "devel:libpixman_1", 72 "devel:libpng16", 73 "devel:libsdl2_2.0", 74 "devel:libslirp", 75 "devel:libsnappy", 76 "devel:libssh2", 77 "devel:libtasn1", 78 "devel:libusb_1.0", 79 "devel:libz", 80 "ninja", 81 ] 82 83 # https://dev.haiku-os.org/ticket/16512 virtio disk1 shows up as 0 (reversed order) 84 BUILD_SCRIPT = """ 85 set -e; 86 rm -rf /tmp/qemu-test.* 87 cd $(mktemp -d /tmp/qemu-test.XXXXXX); 88 mkdir src build; cd src; 89 tar -xf /dev/disk/virtual/virtio_block/0/raw; 90 mkdir -p /usr/bin 91 ln -s /boot/system/bin/env /usr/bin/env 92 cd ../build 93 ../src/configure {configure_opts}; 94 make --output-sync -j{jobs} {target} {verbose}; 95 """ 96 97 def build_image(self, img): 98 self.print_step("Downloading disk image") 99 tarball = self._download_with_cache(self.link, sha256sum=self.csum) 100 101 self.print_step("Extracting disk image") 102 103 subprocess.check_call(["tar", "xzf", tarball, "box.img", "-O"], 104 stdout=open(img, 'wb')) 105 106 self.print_step("Preparing disk image") 107 self.boot(img) 108 109 # Wait for ssh to be available. 110 self.wait_ssh(wait_root=True, cmd="exit 0") 111 112 # Install packages 113 self.ssh_root("pkgman install -y %s" % " ".join(self.requirements)) 114 self.graceful_shutdown() 115 116 self.print_step("All done") 117 118if __name__ == "__main__": 119 sys.exit(basevm.main(HaikuVM, config=HAIKU_CONFIG)) 120