diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/Vagrantfile | 12 | ||||
-rwxr-xr-x | scripts/build-clearfog-image | 158 | ||||
-rwxr-xr-x | scripts/build-config | 87 | ||||
-rwxr-xr-x | scripts/build-flavour | 37 | ||||
-rwxr-xr-x | scripts/build-hyperv-image | 32 | ||||
-rwxr-xr-x | scripts/build-qemu-image | 33 | ||||
-rwxr-xr-x | scripts/build-vagrant-libvirt-box | 74 | ||||
-rwxr-xr-x | scripts/build-vmware-image | 74 | ||||
-rwxr-xr-x | scripts/check-build-env | 71 | ||||
-rwxr-xr-x | scripts/check-config | 32 | ||||
-rwxr-xr-x | scripts/check-vm-build-env | 51 | ||||
-rwxr-xr-x | scripts/copy-image | 7 | ||||
-rw-r--r-- | scripts/defaults.py | 36 | ||||
-rwxr-xr-x | scripts/import-local-packages | 13 | ||||
-rwxr-xr-x | scripts/live-build-config | 60 | ||||
-rwxr-xr-x | scripts/make-version-file | 89 | ||||
-rw-r--r-- | scripts/packer-scripts/vmware.sh | 29 | ||||
-rw-r--r-- | scripts/packer.json | 62 | ||||
-rwxr-xr-x | scripts/pbuilder-config | 54 | ||||
-rwxr-xr-x | scripts/pbuilder-setup | 52 | ||||
-rwxr-xr-x | scripts/pbuilder/hooks/C10shell | 6 | ||||
-rwxr-xr-x | scripts/query-json | 42 | ||||
-rw-r--r-- | scripts/template.ovf | 121 | ||||
-rw-r--r-- | scripts/util.py | 55 |
24 files changed, 1247 insertions, 40 deletions
diff --git a/scripts/Vagrantfile b/scripts/Vagrantfile new file mode 100644 index 00000000..7c89422d --- /dev/null +++ b/scripts/Vagrantfile @@ -0,0 +1,12 @@ +Vagrant.configure("2") do |config| + config.vm.synced_folder './', '/vagrant', + type: "rsync", + owner: 'vyos', + group: 'users', + mount_options: ['dmode=775,fmode=775'] + config.ssh.username = "vyos" + config.ssh.password = "vyos" + config.vm.provider :libvirt do |libvirt| + libvirt.driver = "kvm" + end +end diff --git a/scripts/build-clearfog-image b/scripts/build-clearfog-image new file mode 100755 index 00000000..0ef6d323 --- /dev/null +++ b/scripts/build-clearfog-image @@ -0,0 +1,158 @@ +#!/bin/sh +# +# Copyright (C) 2016 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 or later as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# File: build-clearfog-image +# Purpose: +# Build VyOS image for for Solidrun clearfog. + +lb bootstrap +lb chroot +lb installer +lb binary_chroot +lb chroot_devpts install +lb chroot_proc install +lb chroot_selinuxfs install +lb chroot_sysfs install +lb chroot_hosts install +lb chroot_resolv install +lb chroot_hostname install +lb chroot_sysv-rc install +lb chroot_upstart install +lb chroot_apt install-binary +lb chroot_archives chroot install +lb binary_rootfs +lb binary_manifest +lb binary_package-lists +lb binary_linux-image +lb binary_memtest +lb binary_grub +lb binary_grub2 +lb binary_syslinux +lb binary_disk +lb binary_loadlin +lb binary_win32-loader +lb binary_includes +lb binary_hooks +lb binary_checksums + +# get vyos build version +version=$(cat version) +dateymd=$(date +%Y%m%d) + +# create sd-card image and partition it +qemu-img create -f raw sr-a38x-cf-vyos-"$dateymd"-testing.img 1.8G +parted --script sr-a38x-cf-vyos-"$dateymd"-testing.img mklabel msdos +parted --script sr-a38x-cf-vyos-"$dateymd"-testing.img mkpart primary fat16 8192s 60 +parted --script sr-a38x-cf-vyos-"$dateymd"-testing.img mkpart primary ext2 60 1900 +parted --script sr-a38x-cf-vyos-"$dateymd"-testing.img set 1 boot on + +# mount image and create filesystems +losetup /dev/loop0 sr-a38x-cf-vyos-"$dateymd"-testing.img +partprobe /dev/loop0 +mkfs.vfat -n EFI -F 16 -I /dev/loop0p1 +mkfs.ext2 -L persistence /dev/loop0p2 + +# mount image partitions +mkdir -p /boot/efi +mount /dev/loop0p1 /boot/efi +mkdir -p /mnt +mount /dev/loop0p2 /mnt + +# setup files on image +mkdir -p /mnt/boot/grub +mkdir -p /mnt/boot/"$version"/rw +echo "/ union" > /mnt/persistence.conf +cp binary/live/filesystem.squashfs /mnt/boot/"$version"/"$version.squashfs" +cp binary/live/initrd.img-* /mnt/boot/"$version"/initrd.img +cp binary/live/vmlinuz-* /mnt/boot/"$version"/vmlinuz +cp ../tools/armada-388-clearfog.dtb /boot/efi/armada-388-clearfog.dtb + +# create boot script +cat > /boot/efi/boot.script << EOF +# load DTB +echo "Loading armada-388-clearfog.dtb" +load mmc 0:1 \$fdt_addr_r armada-388-clearfog.dtb +fdt addr \$fdt_addr_r 20000 + +# load efi +echo "Loading EFI image ..." +load mmc 0:1 \$loadaddr EFI/debian/grubarm.efi + +# Sleep a while so the MMC driver can settle down +echo "Sleeping 5 seconds ..." +sleep 5 + +# boot +echo "Booting ..." +bootefi \$loadaddr +EOF + +# compile boot script for u-boot +mkimage -A arm -O linux -T script -C none -a 0 -e 0 -d /boot/efi/boot.script /boot/efi/boot.scr + +# create grub config file to include +cat > load.cfg << EOF +set root=(hd0,msdos2) +set prefix=(hd0,msdos2)/boot/grub +devicetree (hd0,msdos1)/armada-388-clearfog.dtb +insmod normal +normal +EOF + +# create grub menu +cat > /mnt/boot/grub/grub.cfg << EOF +set default=0 +set timeout=5 + +echo -n Press ESC to enter the Grub menu... +if sleep --verbose --interruptible 5 ; then + terminal_input console serial +fi + + +menuentry "VyOS $version (Serial console)" { + linux /boot/"$version"/vmlinuz boot=live quiet vyos-union=/boot/"$version" console=ttyS0,115200n8 + initrd /boot/"$version"/initrd.img +} + +menuentry "Lost password change $version (Serial console)" { + linux /boot/"$version"/vmlinuz boot=live quiet vyos-union=/boot/"$version" console=ttyS0,115200n8 init=/opt/vyatta/sbin/standalone_root_pw_reset + initrd /boot/"$version"/initrd.img +} +EOF + +# install efi grub to image +grub-install --efi-directory /boot/efi --boot-directory /mnt/boot -d /usr/lib/grub/arm-efi /dev/loop0 + +# create grub efi executable +grub-mkimage -O arm-efi -p /boot/grub -d /usr/lib/grub/arm-efi -c load.cfg \ +ext2 iso9660 linux echo configfile \ +search_label search_fs_file search \ +search_fs_uuid ls normal gzio \ +png fat gettext font minicmd \ +gfxterm gfxmenu video video_fb \ +part_msdos part_gpt > /boot/efi/EFI/debian/grubarm.efi + +# unmount image partitions +umount /mnt +umount /boot/efi + +# write u-boot to image +dd if=../tools/u-boot-spl.kwb of=/dev/loop0 bs=512 seek=1 + +# unmount image +sudo losetup -D + +# compress image +xz -v sr-a38x-cf-vyos-"$dateymd"-testing.img diff --git a/scripts/build-config b/scripts/build-config index 7d1aa66b..27a6c7ba 100755 --- a/scripts/build-config +++ b/scripts/build-config @@ -1,4 +1,27 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 +# +# Copyright (C) 2018, VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# File: build-config +# Purpose: +# This script serves the same purpose as ./configure in traditional +# autoconf setups. +# It takes build configuration options from command line, checks them, +# builds a config dictionary, augments it with some default and/or +# computed values and saves it to build/build-config.json +# for other build scripts to read. import argparse import re @@ -19,28 +42,80 @@ def field_to_option(s): def get_default_build_by(): return "{user}@{host}".format(user= getpass.getuser(), host=platform.node()) +def get_validator(optdict, name): + try: + return optdict[name][2] + except KeyError: + return None + +# Options dict format: +# '$option_name_without_leading_dashes': { ('$help_string', $default_value_generator_thunk, $value_checker_thunk) } options = { - 'architecture': ('Image target architecture (amd64 or i586)', lambda: 'amd64', lambda x: x in ['amd64', 'i586']), - 'build-by': ('Builder identifier (e.g. jrandomhacker@example.net)', get_default_build_by, None) + 'architecture': ('Image target architecture (amd64 or i586 or armhf)', lambda: 'amd64', lambda x: x in ['amd64', 'i586', 'armhf']), + 'build-by': ('Builder identifier (e.g. jrandomhacker@example.net)', get_default_build_by, None), + 'debian-mirror': ('Debian repository mirror for ISO build', lambda: defaults.DEBIAN_MIRROR, None), + 'debian-security-mirror': ('Debian security updated mirror', lambda: defaults.DEBIAN_SECURITY_MIRROR, None), + 'pbuilder-debian-mirror': ('Debian repository mirror for pbuilder env bootstrap', lambda: defaults.DEBIAN_MIRROR, None), + 'vyos-mirror': ('VyOS package mirror', lambda: defaults.VYOS_MIRROR, None), + 'build-type': ('Build type, release or development', lambda: 'development', lambda x: x in ['release', 'development']), + 'version': ('Version number (release builds only)', None, None) } # Create the option parser parser = argparse.ArgumentParser() for k, v in options.items(): - parser.add_argument('--' + k, type=str, help=v[0], default=v[1]()) + help_string, default_value_thunk = v[0], v[1] + if default_value_thunk is None: + parser.add_argument('--' + k, type=str, help=help_string) + else: + parser.add_argument('--' + k, type=str, help=help_string, default=default_value_thunk()) + +# The debug option is a bit special since it's different type +parser.add_argument('--debug', help="Enable debug output", action='store_true') args = vars(parser.parse_args()) # Validate options for k, v in args.items(): key = field_to_option(k) - func = options[key][2] + func = get_validator(options, k) if func is not None: if not func(v): print("{v} is not a valid value for --{o} option".format(o=key, v=v)) sys.exit(1) +# Some fixup for mirror settings. +# The idea is: if --debian-mirror is specified but --pbuilder-debian-mirror is not, +# use the --debian-mirror value for both lb and pbuilder bootstrap +if (args['debian_mirror'] != defaults.DEBIAN_MIRROR) and \ + (args['pbuilder_debian_mirror'] == defaults.DEBIAN_MIRROR): + args['pbuilder_debian_mirror'] = args['debian_mirror'] + +# Version can only be set for release builds, +# for dev builds it hardly makes any sense +if args['build_type'] == 'development': + if args['version'] is not None: + print("Version can only be set for release builds") + print("Use --build-type=release option if you want to set version number") + sys.exit(1) + +# Populate some defaults that are not configurable, +# but that are handy to have in the options hash +args['distribution'] = defaults.DEBIAN_DISTRIBUTION +args['build_dir'] = os.path.join(os.getcwd(), defaults.BUILD_DIR) +args['pbuilder_config'] = defaults.PBUILDER_CONFIG +args['vyos_branch'] = defaults.VYOS_BRANCH + +# Check the build environment and dependencies +env_check_retval = os.system("scripts/check-build-env") +if env_check_retval > 0: + print("Build environment check failed, fix the issues and retry") + + # Save to file +os.makedirs(defaults.BUILD_DIR, exist_ok=True) +print("Saving the build config to {0}".format(defaults.BUILD_CONFIG)) with open(defaults.BUILD_CONFIG, 'w') as f: - json.dump(args, f) + json.dump(args, f, indent=4, sort_keys=True) + print("\n", file=f) diff --git a/scripts/build-flavour b/scripts/build-flavour new file mode 100755 index 00000000..c14f5735 --- /dev/null +++ b/scripts/build-flavour @@ -0,0 +1,37 @@ +#!/bin/sh +# Copyright (C) 2016 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# File: build-flavour +# Purpose: Adds various data files to the build config +# depending on the build flavour. + + +BUILD_TYPE=$(scripts/query-json build/build-config.json build_type) +BUILD_ARCH=$(scripts/query-json build/build-config.json architecture) + +# Add debug tools if it's a development image +if [ $BUILD_TYPE = "development" ]; then + cp data/package-lists/vyos-dev.list.chroot build/config/package-lists/ +fi + +# Install grub-pc if it's an x86 build +if [ $BUILD_ARCH = 'amd64' -o $BUILD_ARCH = 'i686' ]; then + cp data/package-lists/vyos-x86.list.chroot build/config/package-lists/ +fi + +# Install grub-efi-arm if it's an arm build +if [ $BUILD_ARCH = 'armhf' -o $BUILD_ARCH = 'armel' -o $BUILD_ARCH = 'arm' ]; then + cp data/package-lists/vyos-arm.list.chroot build/config/package-lists/ +fi diff --git a/scripts/build-hyperv-image b/scripts/build-hyperv-image new file mode 100755 index 00000000..40c0c828 --- /dev/null +++ b/scripts/build-hyperv-image @@ -0,0 +1,32 @@ +#!/bin/sh +# +# Copyright (C) 2016 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# File: build-hyperv-image +# Purpose: +# Build VyOS image for Hyper-V. + +export PACKER_BUILD_DIR=packer_build + +DST_DIR=${PACKER_BUILD_DIR}/hyperv +mkdir -p ${DST_DIR} + +# Convert raw image to VHD +source_image=${PACKER_BUILD_DIR}/qemu/vyos_qemu_image.img +vhd=${DST_DIR}/vyos_hyperv_image.vhd +qemu-img convert -f raw ${source_image} -O vpc ${vhd} +if [ "$?" = "0" ]; then + echo "Hyper-V image successfully created to ./${vhd}" +fi diff --git a/scripts/build-qemu-image b/scripts/build-qemu-image new file mode 100755 index 00000000..29cb6cf1 --- /dev/null +++ b/scripts/build-qemu-image @@ -0,0 +1,33 @@ +#!/bin/sh +# +# Copyright (C) 2016 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# File: build-qemu-image +# Purpose: +# Build VyOS raw image for qemu. + +BUILD_DIR=$(scripts/query-json build/build-config.json build_dir) +BUILD_ARCH=$(scripts/query-json build/build-config.json architecture) +export VERSION=$(cat $BUILD_DIR/version) + +export ISO_IMAGE=./build/live-image-$BUILD_ARCH.hybrid.iso +export ISO_MD5_SUM=$(md5sum ${ISO_IMAGE} | awk '{print $1}') +export PACKER_BUILD_DIR=packer_build +export PACKER_LOG_PATH=${PACKER_BUILD_DIR}/build.log +export PACKER_LOG=1 + +mkdir -p ${PACKER_BUILD_DIR} + +packer build -only=qemu-image scripts/packer.json diff --git a/scripts/build-vagrant-libvirt-box b/scripts/build-vagrant-libvirt-box new file mode 100755 index 00000000..6db77c2a --- /dev/null +++ b/scripts/build-vagrant-libvirt-box @@ -0,0 +1,74 @@ +#!/bin/sh +# +# Copyright (C) 2016 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# File: build-vagrant-libvirt-box +# Purpose: +# Build VyOS Vagrant libvirt box. + +export PACKER_BUILD_DIR=packer_build + +DST_DIR=${PACKER_BUILD_DIR}/vagrant-libvirt +BOX_DIR=${DST_DIR}/box +mkdir -p ${BOX_DIR} + +# Copy qcow2 image +cp -p packer_build/qemu/vyos_qemu_image.img ${BOX_DIR}/box.img + +# Put metadata.json and Vagrantfile +echo '{"format":"qcow2","provider":"libvirt","virtual_size":4}' > ${BOX_DIR}/metadata.json +cat <<EOF > ${BOX_DIR}/Vagrantfile +Vagrant.configure("2") do |config| + config.vm.synced_folder './', '/vagrant', + type: "rsync", + owner: 'vyos', + group: 'users', + mount_options: ['dmode=775,fmode=775'] + config.ssh.username = "vyos" + config.ssh.password = "vyos" + config.vm.provider :libvirt do |libvirt| + libvirt.driver = "kvm" + end +end +EOF + +# Create box +box=${DST_DIR}/vyos_vagrant_libvirt.box +tar -C ${BOX_DIR} -czvf ${box} metadata.json Vagrantfile box.img +if [ "$?" = "0" ]; then + echo "Vagrant libvirt box successfully created to ./${box}" +fi + +PROVIDER=libvirt + +# Create version +major=$(cat build/version | cut -d'+' -f2 | cut -d'-' -f1 | rev | cut -c 5- | rev) +sub=$(cat build/version | cut -d'+' -f2 | cut -d'-' -f1 | rev | cut -c 3-4 | rev) +minor=$(cat build/version | cut -d'+' -f2 | cut -d'-' -f1 | rev | cut -c 1-2 | rev) +version=$(echo "$major.$sub.$minor") +curl -XPOST -d "version[version]=${version}" \ + https://app.vagrantup.com/api/v1/box/${VAGRANT_BOX_NAME}/versions?access_token=${VAGRANT_CLOUD_ACCESS_TOKEN} +echo + +# Create provider +urlencoded_version=$(cat build/version | sed 's/+/%2B/') +curl -XPOST -d "provider[name]=${PROVIDER}" -d "provider[url]=${VAGRANT_BOX_BASE_URL}/vyos-${urlencoded_version}-vagrant-${PROVIDER}.box" \ + https://app.vagrantup.com/api/v1/box/${VAGRANT_BOX_NAME}/version/${version}/providers?access_token=${VAGRANT_CLOUD_ACCESS_TOKEN} +echo + +# Release version +curl -XPUT \ + https://app.vagrantup.com/api/v1/box/${VAGRANT_BOX_NAME}/version/${version}/release?access_token=${VAGRANT_CLOUD_ACCESS_TOKEN} +echo diff --git a/scripts/build-vmware-image b/scripts/build-vmware-image new file mode 100755 index 00000000..1730d7a3 --- /dev/null +++ b/scripts/build-vmware-image @@ -0,0 +1,74 @@ +#!/bin/sh +# +# Copyright (C) 2016 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# File: build-vmware-image +# Purpose: +# Build VyOS OVA and OVF for VMware. + +if [ ! $(which vmdk-convert) ]; then + echo "Your system doesn't have vmdk-convert. Please install it from https://github.com/vmware/open-vmdk." + exit 1 +else + echo "Your system has vmdk-convert." +fi + +if [ ! $(which ovftool) ]; then + echo "Your system doesn't have ovftool. Please install it from https://www.vmware.com/support/developer/ovf/." + exit 1 +else + echo "Your system has ovftool." +fi + +export PACKER_BUILD_DIR=packer_build + +DST_DIR=${PACKER_BUILD_DIR}/vmware +mkdir -p ${DST_DIR} + +# Convert qcow2 image to VMDK +source_image=${PACKER_BUILD_DIR}/qemu/vyos_qemu_image.img +tmp_vmdk=${DST_DIR}/tmp.vmdk +vmdk=${DST_DIR}/vyos_vmware_image.vmdk +ovf=${DST_DIR}/vyos_vmware_image.ovf +qemu-img convert -f qcow2 ${source_image} -O vmdk -o adapter_type=lsilogic ${tmp_vmdk} +vmdk-convert ${tmp_vmdk} ${vmdk} + +# Generate OVF +echo 'Generating OVF file...' +vmdk_file_size=$(du --bytes ${vmdk} | cut -f1) +vmdk_populated_size=$(vmdk-convert -i ${vmdk} | jq .used) +version=$(cat build/version) +sed scripts/template.ovf \ + -e "s/{{vmdk_file_size}}/${vmdk_file_size}/" \ + -e "s/{{vmdk_populated_size}}/${vmdk_populated_size}/" \ + -e "s/{{version}}/${version}/" \ + > ${ovf} + +# Generate manifest file +cd ${DST_DIR} +openssl sha1 *.vmdk *.ovf > vyos_vmware_image.mf + +# Convert the OVF to signed OVA... +echo 'Converting the OVF to signed OVA...' +private_key=${PRIVATE_KEY_PATH:-"../../key/privatekey.pem"} +if [ ! -f ${private_key} ]; then + echo 'Please put your key to "key/privatekey.pem" in repository root, or set PRIVATE_KEY_PATH to environment variables.' + exit 1 +fi +ovftool --privateKey=${PRIVATE_KEY_PATH} vyos_vmware_image.ovf vyos_vmware_image-signed.ova + +# Convert the OVF to signed OVF... +echo 'Converting the OVF to signed OVF...' +ovftool --privateKey=${PRIVATE_KEY_PATH} vyos_vmware_image.ovf vyos_vmware_image-signed.ovf diff --git a/scripts/check-build-env b/scripts/check-build-env index 11e1c66b..7377be64 100755 --- a/scripts/check-build-env +++ b/scripts/check-build-env @@ -1,35 +1,54 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 +# +# Copyright (C) 2015 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# File: check-build-env +# Purpose: +# Checks if packages required for package and ISO image build +# are installed. + import os import sys -required_packages = [ - 'make', - 'live-build', - 'pbuilder', - 'devscripts', - 'python-pystache' -] - - -def is_installed(name): - result = os.system("dpkg-query -W --showformat='${{Status}}\n' {name} 2>&1 | grep 'install ok installed' >/dev/null".format(name=name)) - return True if result == 0 else False - - -missing_packages = [] +import util + +deps = { + 'packages': [ + 'sudo', + 'make', + 'live-build', + 'pbuilder', + 'devscripts', + 'python3-pystache', + 'python3-git' + ], + 'binaries': [] +} print("Checking if packages required for VyOS image build are installed") -for p in required_packages: - if not is_installed(p): - missing_packages.append(p) +checker = util.DependencyChecker(deps) -if missing_packages: - print("Your system does not have some of the required packages installed.") - print("Please install the following packages:") - print(" ".join(missing_packages)) - sys.exit(1) -else: - print("All required packages are installed") +missing = checker.get_missing_dependencies() +if not missing: + print("All dependencies are installed") sys.exit(0) +else: + checker.print_missing_deps() + sys.exit(1) + +sys.exit(0) + diff --git a/scripts/check-config b/scripts/check-config index 3949869b..d2236619 100755 --- a/scripts/check-config +++ b/scripts/check-config @@ -1,14 +1,38 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 +# +# Copyright (C) 2015 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# File: check-config +# Purpose: +# Checks if the build config file (build/build-config.json) exists. +# This is to prevent accidental execution of plumbing make targets +# from going too far and failing with confusing errors. + import sys -import os +import json import defaults print("Checking build configuration") -if not os.path.exists(defaults.BUILD_CONFIG): - print("Build config does not exist") +try: + with open(defaults.BUILD_CONFIG, 'r') as f: + build_config = json.load(f) +except: + print("Build config does not exist or is not a valid JSON file") print("Please run the ./configure script and try again") sys.exit(1) diff --git a/scripts/check-vm-build-env b/scripts/check-vm-build-env new file mode 100755 index 00000000..8efab848 --- /dev/null +++ b/scripts/check-vm-build-env @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2016 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# File: check-vm-build-env +# Purpose: +# Checks if packages required for VM image build are installed. + + +import os +import sys + +import util + +deps = { + 'packages': [ + 'jq', + 'qemu-system-x86', + 'qemu-utils' + ], + 'binaries': ['packer'] +} + +print("Checking if packages required for VyOS image build are installed") + +checker = util.DependencyChecker(deps) + +missing = checker.get_missing_dependencies() +if not missing: + print("All dependencies are installed") + sys.exit(0) +else: + checker.print_missing_deps() + if 'packer' in missing['binaries']: + print("Your system does not have Packer.") + print("Please install Packer from https://www.packer.io/downloads.html.") + sys.exit(1) + +sys.exit(0) diff --git a/scripts/copy-image b/scripts/copy-image new file mode 100755 index 00000000..01af511d --- /dev/null +++ b/scripts/copy-image @@ -0,0 +1,7 @@ +#!/bin/sh + +BUILD_DIR=$(scripts/query-json build/build-config.json build_dir) +BUILD_ARCH=$(scripts/query-json build/build-config.json architecture) +VERSION=$(cat $BUILD_DIR/version) + +ln -nsf $BUILD_DIR/live-image-$BUILD_ARCH.hybrid.iso $BUILD_DIR/vyos-$VERSION-$BUILD_ARCH.iso diff --git a/scripts/defaults.py b/scripts/defaults.py index 96dfcc98..93eadc30 100644 --- a/scripts/defaults.py +++ b/scripts/defaults.py @@ -1,4 +1,40 @@ +# Copyright (C) 2018 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# File: defaults.py +# Purpose: Various default values for use in build scripts. + + import os BUILD_DIR = 'build' BUILD_CONFIG = os.path.join(BUILD_DIR, 'build-config.json') + +# The default mirror was chosen entirely at random +DEBIAN_MIRROR = 'http://deb.debian.org/debian' +DEBIAN_SECURITY_MIRROR = 'http://deb.debian.org/debian-security' + +DEBIAN_DISTRIBUTION = 'jessie' + +PBUILDER_CONFIG = os.path.join(BUILD_DIR, 'pbuilderrc') +PBUILDER_DIR = os.path.join(BUILD_DIR, 'pbuilder') + +LB_CONFIG_DIR = os.path.join(BUILD_DIR, 'config') +CHROOT_INCLUDES_DIR = os.path.join(LB_CONFIG_DIR, 'includes.chroot') + +VYOS_MIRROR = 'http://dev.packages.vyos.net/repositories/current' + +VYOS_BRANCH = 'current' + +VYOS_REPO_FILE = 'config/archives/vyos.list.chroot' diff --git a/scripts/import-local-packages b/scripts/import-local-packages new file mode 100755 index 00000000..70b4c365 --- /dev/null +++ b/scripts/import-local-packages @@ -0,0 +1,13 @@ +#!/bin/sh + +LOCAL_PKG_DIR=build/config/packages.chroot + +mkdir -p $LOCAL_PKG_DIR + +FILES=packages/*.deb +for f in $FILES +do + if [ -e "$f" ]; then + cp $f $LOCAL_PKG_DIR + fi +done diff --git a/scripts/live-build-config b/scripts/live-build-config index 59f0bbb2..b1a77b4c 100755 --- a/scripts/live-build-config +++ b/scripts/live-build-config @@ -1,4 +1,24 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 +# +# Copyright (C) 2018 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# File: live-build-config +# Purpose: +# Creates a live-build config command from template using the build config +# and executes it, to prepare the system for building the installation ISO. + import sys import os @@ -14,7 +34,9 @@ util.check_build_config() lb_config_tmpl = """ lb config noauto \ --architectures {{architecture}} \ - --bootappend-live "boot=live components hostname=vyos username=live" \ + --bootappend-live "boot=live components hostname=vyos username=live nopersistence noautologin nonetworking union=overlay" \ + --linux-flavours {{architecture}}-vyos \ + --linux-packages linux-image-4.14.26 \ --bootloader syslinux \ --binary-images iso-hybrid \ --debian-installer false \ @@ -22,18 +44,48 @@ lb config noauto \ --iso-application "VyOS" \ --iso-publisher "{{build_by}}" \ --iso-volume "VyOS" \ - --debootstrap-options "--variant=minbase --exclude=isc-dhcp-client,isc-dhcp-common,ifupdown" \ + --debootstrap-options "--variant=minbase --exclude=isc-dhcp-client,isc-dhcp-common,ifupdown --include=apt-transport-https" \ + --mirror-bootstrap {{debian_mirror}} \ + --mirror-chroot {{debian_mirror}} \ + --mirror-chroot-security {{debian_security_mirror}} \ + --mirror-binary {{debian_mirror}} \ + --mirror-binary-security {{debian_security_mirror}} \ + --archive-areas "main contrib non-free" \ + --firmware-chroot true \ + --updates true \ + --security true \ + --apt-indices false "${@}" """ with open(defaults.BUILD_CONFIG, 'r') as f: build_config = json.load(f) +debug = build_config['debug'] + +# Add the additional repositories to package lists +print("Setting up additional APT entries") +vyos_repo_entry = "deb {0}/vyos {1} main\n".format(build_config['vyos_mirror'], build_config['vyos_branch']) +vyos_debian_repo_entry = "deb {0}/debian {1} main\n".format(build_config['vyos_mirror'], build_config['vyos_branch']) + +apt_file = os.path.join(build_config['build_dir'], defaults.VYOS_REPO_FILE) + +if debug: + print("Adding these entries to {0}:".format(apt_file)) + print("\t", vyos_repo_entry) + print("\t", vyos_debian_repo_entry) + +with open(apt_file, 'w') as f: + f.write(vyos_repo_entry) + f.write(vyos_debian_repo_entry) + +# Configure live-build + lb_config_command = pystache.render(lb_config_tmpl, build_config) print("Configuring live-build") -os.chdir(defaults.BUILD_DIR) +os.chdir(defaults.BUILD_DIR) result = os.system(lb_config_command) if result > 0: print("live-build config failed") diff --git a/scripts/make-version-file b/scripts/make-version-file new file mode 100755 index 00000000..95574722 --- /dev/null +++ b/scripts/make-version-file @@ -0,0 +1,89 @@ +#!/usr/bin/python3 +# +# Copyright (C) 2018 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# File: make-version-file +# Purpose: +# Creates version file in live-build chroot includes dir +# that is included in the image and used by 'show version' command +# and install/upgrade scripts. + +import os +import datetime +import json +import uuid + +import git + +import defaults +import util + +# Load the build config +util.check_build_config() +with open(defaults.BUILD_CONFIG, 'r') as f: + build_config = json.load(f) + +# Create a build timestamp +now = datetime.datetime.today() +build_timestamp = now.strftime("%Y%m%d%H%M") + +# FIXME: use aware rather than naive object +build_date = now.strftime("%a %d %b %Y %H:%M UTC") + +# Assign a (hopefully) unique identifier to the build (UUID) +build_id = str(uuid.uuid4()) + +# Create a build version +if build_config['build_type'] == 'development': + try: + # Load the branch to version mapping file + with open('data/versions') as f: + version_mapping = json.load(f) + + repo = git.Repo('.') + git_branch = repo.active_branch.name + branch_version = version_mapping[git_branch] + + version = "{0}-rolling+{1}".format(branch_version, build_timestamp) + except Exception as e: + print("Could not build a version string specific to git branch, falling back to default: {0}".format(str(e))) + version = "999.{0}".format(build_timestamp) +else: + # Release build, use the version from ./configure arguments + version = build_config['version'] + +version_data = { + 'version': version, + 'built_by': build_config['build_by'], + 'built_on': build_date, + 'build_id': build_id +} + + +os.makedirs(os.path.join(defaults.CHROOT_INCLUDES_DIR, 'usr/share/vyos'), exist_ok=True) +with open(os.path.join(defaults.CHROOT_INCLUDES_DIR, 'usr/share/vyos/version.json'), 'w') as f: + json.dump(version_data, f) + +# For backwards compatibility with 'add system image' script from older versions +# we need a file in old format so that script can find out the version of the image +# for upgrade +with open(os.path.join(defaults.CHROOT_INCLUDES_DIR, 'opt/vyatta/etc/version'), 'w') as f: + print("Version: {0}".format(version), file=f) + +# Leaky abstraction: we want ISO file name include version number, +# but we probably don't want to have a separate build step just for this, +# neither we want to use lengthy paths in makefiles +with open(os.path.join(defaults.BUILD_DIR, 'version'), 'w') as f: + print(version, file=f) diff --git a/scripts/packer-scripts/vmware.sh b/scripts/packer-scripts/vmware.sh new file mode 100644 index 00000000..60c4db7e --- /dev/null +++ b/scripts/packer-scripts/vmware.sh @@ -0,0 +1,29 @@ +#!/bin/vbash +source /opt/vyatta/etc/functions/script-template + +# Add Debian Jessie repository +set system package repository jessie url 'http://ftp.nl.debian.org/debian/' +set system package repository jessie distribution 'jessie' +set system package repository jessie components 'main contrib non-free' +commit +save + +# Install open-vm-tools +sudo apt-get update +sudo apt-get -y install open-vm-tools + +# Delete Debian Jessie repository +delete system package repository jessie +commit +save + +# Removing leftover leases and persistent rules +sudo rm -f /var/lib/dhcp3/* + +# Removing apt caches +sudo rm -rf /var/cache/apt/* + +# Removing hw-id +delete interfaces ethernet eth0 hw-id +commit +save diff --git a/scripts/packer.json b/scripts/packer.json new file mode 100644 index 00000000..218b2a85 --- /dev/null +++ b/scripts/packer.json @@ -0,0 +1,62 @@ +{ + "variables": { + "iso_url": "{{env `ISO_IMAGE`}}", + "iso_checksum": "{{env `ISO_MD5_SUM`}}", + "output_directory": "{{env `PACKER_BUILD_DIR`}}" + }, + "builders": + [ + { + "name": "qemu-image", + "type": "qemu", + "iso_url": "{{user `iso_url`}}", + "iso_checksum": "{{user `iso_checksum`}}", + "iso_checksum_type": "md5", + "output_directory": "{{user `output_directory`}}/qemu", + "shutdown_command": "sudo halt -p", + "disk_size": 4096, + "format": "qcow2", + "headless": true, + "ssh_host_port_min": 2222, + "ssh_host_port_max": 2229, + "ssh_username": "vyos", + "ssh_password": "vyos", + "ssh_port": 22, + "ssh_wait_timeout": "300s", + "vm_name": "vyos_qemu_image.img", + "net_device": "virtio-net", + "disk_interface": "virtio", + "boot_wait": "5s", + "boot_command": + [ + "<enter><wait3m>", + "vyos<enter><wait5>", + "vyos<wait><enter><wait10>", + "install image<enter><wait5>", + "<enter><wait5>", + "<enter><wait5>", + "<enter><wait5>", + "Yes<enter><wait5>", + "<enter><wait10>", + "<enter><wait5>", + "<enter><wait5>", + "vyos<enter><wait5>", + "vyos<enter><wait10>", + "<enter><wait10><wait10>", + "reboot<enter><wait5>", + "Yes<enter><wait3m>", + "vyos<enter><wait5>", + "vyos<enter><wait10>", + "configure<enter><wait5>", + "set interface ethernet eth0 address dhcp<enter><wait5>", + "set service ssh<enter><wait5>", + "commit<enter><wait5>", + "save<enter><wait5>", + "delete interface ethernet eth0 hw-id<enter><wait5>", + "commit<enter><wait5>", + "save<enter><wait5>", + "exit<enter><wait5>" + ] + } + ] +} diff --git a/scripts/pbuilder-config b/scripts/pbuilder-config new file mode 100755 index 00000000..06e14cbf --- /dev/null +++ b/scripts/pbuilder-config @@ -0,0 +1,54 @@ +#!/usr/bin/env python +# +# Copyright (C) 2015 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# File: pbuilder-config +# Purpose: +# Generates a pbuilderrc file for use by package build scripts. + + +import sys +import os +import json + +import pystache + +import defaults +import util + +util.check_build_config() + +pbuilder_config_tmpl = """ + +BASETGZ={{build_dir}}/base.tgz +BUILDPLACE={{build_dir}}/pbuilder/ +MIRRORSITE={{pbuilder_debian_mirror}} +BUILDRESULT={{build_dir}}/pbuilder/result/ + +DISTRIBUTION={{distribution}} + +ARCHITECTURE={{architecture}} + +""" + +with open(defaults.BUILD_CONFIG, 'r') as f: + build_config = json.load(f) + +pbuilder_config = pystache.render(pbuilder_config_tmpl, build_config) + +print("Configuring pbuilder") + +with open(defaults.PBUILDER_CONFIG, 'w+') as f: + f.write(pbuilder_config) diff --git a/scripts/pbuilder-setup b/scripts/pbuilder-setup new file mode 100755 index 00000000..a89348b8 --- /dev/null +++ b/scripts/pbuilder-setup @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2015 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# File: pbuilder-setup +# Purpose: +# Bootstraps a Debian environment for use by pbuilder. + + +import sys +import os +import json +import distutils.dir_util + +import pystache + +import defaults +import util + +util.check_build_config() + +pbuilder_create_cmd_tmpl= """ + sudo pbuilder --create \ + --configfile {{pbuilder_config}} +""" + +with open(defaults.BUILD_CONFIG, 'r') as f: + build_config = json.load(f) + +pbuilder_create_command = pystache.render(pbuilder_create_cmd_tmpl, build_config) + +print("Creating a pbuilder environment") +#os.chdir(defaults.BUILD_DIR) + +distutils.dir_util.mkpath(defaults.PBUILDER_DIR) + +result = os.system(pbuilder_create_command) +if result > 0: + print("pbuilder environment bootstrap failed") + sys.exit(1) diff --git a/scripts/pbuilder/hooks/C10shell b/scripts/pbuilder/hooks/C10shell new file mode 100755 index 00000000..f56f9f7f --- /dev/null +++ b/scripts/pbuilder/hooks/C10shell @@ -0,0 +1,6 @@ +#!/bin/sh +# invoke shell if build fails. + +apt-get install -y --force-yes vim nano less bash +cd /tmp/buildd/*/debian/.. +/bin/bash < /dev/tty > /dev/tty 2> /dev/tty diff --git a/scripts/query-json b/scripts/query-json new file mode 100755 index 00000000..2f1ea32f --- /dev/null +++ b/scripts/query-json @@ -0,0 +1,42 @@ +#!/usr/bin/python3 +# +# Copyright (C) 2016 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# File: query-config +# Purpose: Extracts field values from a flat JSON file, +# for use in languages that can't handle JSON easily, +# (I'm looking at you, Bourne shell!) + + +import sys +import json + +import defaults +import util + +if len(sys.argv) < 3: + print("Usage: {0} <flat JSON file> <config field name>".format(sys.argv[0])) + sys.exit(1) + +# Note: lack of error handling is deliberate, if some field is expected to be there +# but isn't, it's better if the failure will be obvious and spectacular + +file = sys.argv[1] +key = sys.argv[2] + +with open(file, 'r') as f: + json_data = json.load(f) + +print(json_data[key]) diff --git a/scripts/template.ovf b/scripts/template.ovf new file mode 100644 index 00000000..f3624339 --- /dev/null +++ b/scripts/template.ovf @@ -0,0 +1,121 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Envelope vmw:buildId="build-3018522" xmlns="http://schemas.dmtf.org/ovf/envelope/1" xmlns:cim="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vmw="http://www.vmware.com/schema/ovf" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <References> + <File ovf:href="vyos_vmware_image.vmdk" ovf:id="file1" ovf:size="{{vmdk_file_size}}"/> + </References> + <DiskSection> + <Info>Virtual disk information</Info> + <Disk ovf:capacity="4" ovf:capacityAllocationUnits="byte * 2^30" ovf:diskId="vmdisk1" ovf:fileRef="file1" ovf:format="http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized" ovf:populatedSize="{{vmdk_populated_size}}"/> + </DiskSection> + <NetworkSection> + <Info>The list of logical networks</Info> + <Network ovf:name="VM Network"> + <Description>The VM Network network</Description> + </Network> + </NetworkSection> + <VirtualSystem ovf:id="vm"> + <Info>A virtual machine</Info> + <Name>vyos</Name> + <OperatingSystemSection ovf:id="1" vmw:osType="other26xLinux64Guest"> + <Info>The kind of installed guest operating system</Info> + </OperatingSystemSection> + <VirtualHardwareSection> + <Info>Virtual hardware requirements</Info> + <System> + <vssd:ElementName>Virtual Hardware Family</vssd:ElementName> + <vssd:InstanceID>0</vssd:InstanceID> + <vssd:VirtualSystemIdentifier>vyos</vssd:VirtualSystemIdentifier> + <vssd:VirtualSystemType>vmx-09</vssd:VirtualSystemType> + </System> + <Item> + <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits> + <rasd:Description>Number of Virtual CPUs</rasd:Description> + <rasd:ElementName>1 virtual CPU(s)</rasd:ElementName> + <rasd:InstanceID>1</rasd:InstanceID> + <rasd:ResourceType>3</rasd:ResourceType> + <rasd:VirtualQuantity>1</rasd:VirtualQuantity> + </Item> + <Item> + <rasd:AllocationUnits>byte * 2^30</rasd:AllocationUnits> + <rasd:Description>Memory Size</rasd:Description> + <rasd:ElementName>1GB of memory</rasd:ElementName> + <rasd:InstanceID>2</rasd:InstanceID> + <rasd:ResourceType>4</rasd:ResourceType> + <rasd:VirtualQuantity>1</rasd:VirtualQuantity> + </Item> + <Item> + <rasd:Address>0</rasd:Address> + <rasd:Description>SCSI Controller</rasd:Description> + <rasd:ElementName>scsiController0</rasd:ElementName> + <rasd:InstanceID>3</rasd:InstanceID> + <rasd:ResourceSubType>lsilogic</rasd:ResourceSubType> + <rasd:ResourceType>6</rasd:ResourceType> + </Item> + <Item> + <rasd:Address>1</rasd:Address> + <rasd:Description>IDE Controller</rasd:Description> + <rasd:ElementName>ideController1</rasd:ElementName> + <rasd:InstanceID>4</rasd:InstanceID> + <rasd:ResourceType>5</rasd:ResourceType> + </Item> + <Item ovf:required="false"> + <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation> + <rasd:ElementName>serial0</rasd:ElementName> + <rasd:InstanceID>5</rasd:InstanceID> + <rasd:ResourceType>21</rasd:ResourceType> + <vmw:Config ovf:required="false" vmw:key="yieldOnPoll" vmw:value="false"/> + </Item> + <Item ovf:required="false"> + <rasd:AddressOnParent>0</rasd:AddressOnParent> + <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation> + <rasd:ElementName>cdrom0</rasd:ElementName> + <rasd:InstanceID>6</rasd:InstanceID> + <rasd:Parent>5</rasd:Parent> + <rasd:ResourceType>15</rasd:ResourceType> + </Item> + <Item> + <rasd:AddressOnParent>0</rasd:AddressOnParent> + <rasd:ElementName>disk0</rasd:ElementName> + <rasd:HostResource>ovf:/disk/vmdisk1</rasd:HostResource> + <rasd:InstanceID>7</rasd:InstanceID> + <rasd:Parent>3</rasd:Parent> + <rasd:ResourceType>17</rasd:ResourceType> + </Item> + <Item> + <rasd:AddressOnParent>2</rasd:AddressOnParent> + <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation> + <rasd:Connection>VM Network</rasd:Connection> + <rasd:Description>VmxNet3 ethernet adapter on "VM Network"</rasd:Description> + <rasd:ElementName>ethernet0</rasd:ElementName> + <rasd:InstanceID>8</rasd:InstanceID> + <rasd:ResourceSubType>VmxNet3</rasd:ResourceSubType> + <rasd:ResourceType>10</rasd:ResourceType> + <vmw:Config ovf:required="false" vmw:key="wakeOnLanEnabled" vmw:value="false"/> + </Item> + <Item ovf:required="false"> + <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation> + <rasd:ElementName>video</rasd:ElementName> + <rasd:InstanceID>9</rasd:InstanceID> + <rasd:ResourceType>24</rasd:ResourceType> + </Item> + <Item ovf:required="false"> + <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation> + <rasd:ElementName>vmci</rasd:ElementName> + <rasd:InstanceID>10</rasd:InstanceID> + <rasd:ResourceSubType>vmware.vmci</rasd:ResourceSubType> + <rasd:ResourceType>1</rasd:ResourceType> + </Item> + <vmw:Config ovf:required="false" vmw:key="cpuHotAddEnabled" vmw:value="true"/> + <vmw:Config ovf:required="false" vmw:key="memoryHotAddEnabled" vmw:value="true"/> + <vmw:Config ovf:required="false" vmw:key="powerOpInfo.powerOffType" vmw:value="soft"/> + <vmw:Config ovf:required="false" vmw:key="powerOpInfo.resetType" vmw:value="soft"/> + <vmw:Config ovf:required="false" vmw:key="powerOpInfo.suspendType" vmw:value="soft"/> + </VirtualHardwareSection> + <ProductSection> + <Info>VyOS is a Linux-based network operating system that provides software-based network routing, firewall, and VPN functionality.</Info> + <Product>VyOS</Product> + <Vendor>VyOS maintainers and contributors</Vendor> + <Version>{{version}}</Version> + </ProductSection> + </VirtualSystem> +</Envelope> diff --git a/scripts/util.py b/scripts/util.py index 740d4ccc..7cc33364 100644 --- a/scripts/util.py +++ b/scripts/util.py @@ -1,5 +1,25 @@ +# Copyright (C) 2015 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# File: util.py +# Purpose: +# Various common functions for use in build scripts. + + import sys import os +from distutils.spawn import find_executable import defaults @@ -8,3 +28,38 @@ def check_build_config(): print("Build config file ({file}) does not exist".format(file=defaults.BUILD_CONFIG)) print("If you are running this script by hand, you should better not. Run 'make iso' instead.") sys.exit(1) + + +class DependencyChecker(object): + def __init__(self, spec): + missing_packages = self._get_missing_packages(spec['packages']) + missing_binaries = self._get_missing_binaries(spec['binaries']) + self.__missing = {'packages': missing_packages, 'binaries': missing_binaries} + + + def _package_installed(self, name): + result = os.system("dpkg-query -W --showformat='${{Status}}\n' {name} 2>&1 | grep 'install ok installed' >/dev/null".format(name=name)) + return True if result == 0 else False + + def _get_missing_packages(self, packages): + missing_packages = [] + for p in packages: + if not self._package_installed(p): + missing_packages.append(p) + return missing_packages + + def _get_missing_binaries(self, binaries): + missing_binaries = [] + for b in binaries: + if not find_executable(b): + missing_binaries.append(b) + return missing_binaries + + def get_missing_dependencies(self): + if self.__missing['packages'] or self.__missing['binaries']: + return self.__missing + return None + + def print_missing_deps(self): + print("Missing packages: " + " ".join(self.__missing['packages'])) + print("Missing binaries: " + " ".join(self.__missing['binaries'])) |