From 3e56d7456e55b46ceb1dbca6a8f5cbc5150e18f5 Mon Sep 17 00:00:00 2001 From: Yuya Kusakabe Date: Fri, 4 Mar 2016 14:33:32 +0900 Subject: Add qemu image build scripts --- scripts/check-vm-build-env | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 scripts/check-vm-build-env (limited to 'scripts/check-vm-build-env') diff --git a/scripts/check-vm-build-env b/scripts/check-vm-build-env new file mode 100755 index 00000000..290b28c8 --- /dev/null +++ b/scripts/check-vm-build-env @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# +# 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 . +# +# File: check-vm-build-env +# Purpose: +# Checks if packages required for VM image build are installed. + + +import os +import sys +from distutils.spawn import find_executable + +required_packages = [ + 'make', + 'qemu-system-x86', + 'qemu-utils' +] + + +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 = [] + +print("Checking if packages required for VyOS VM image build are installed") + +for p in required_packages: + if not is_installed(p): + missing_packages.append(p) + +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") + +if find_executable("packer"): + print("Your system has Packer.") +else: + print("Your system does not have Packer.") + print("Please install Packer from https://www.packer.io/downloads.html.") + sys.exit(1) + +sys.exit(0) -- cgit v1.2.3 From 08a6856b3c8f3146343647f996fca9c48fb4e960 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Fri, 4 Mar 2016 15:05:03 -0500 Subject: Factor out dependency checking functions to its own class (ref T9). --- scripts/check-build-env | 49 ++++++++++++++++++++++------------------------ scripts/check-vm-build-env | 48 ++++++++++++++++++--------------------------- scripts/util.py | 36 ++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 55 deletions(-) (limited to 'scripts/check-vm-build-env') diff --git a/scripts/check-build-env b/scripts/check-build-env index 6f08847f..6dcf885b 100755 --- a/scripts/check-build-env +++ b/scripts/check-build-env @@ -23,34 +23,31 @@ import os import sys -required_packages = [ - 'sudo', - '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', + 'python-pystache' + ], + '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-vm-build-env b/scripts/check-vm-build-env index 290b28c8..47ec5922 100755 --- a/scripts/check-vm-build-env +++ b/scripts/check-vm-build-env @@ -21,41 +21,31 @@ import os import sys -from distutils.spawn import find_executable -required_packages = [ - 'make', - 'qemu-system-x86', - 'qemu-utils' -] +import util +deps = { + 'packages': [ + 'make', + 'qemu-system-x86', + 'qemu-utils' + ], + 'binaries': ['packer'] +} -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 +print("Checking if packages required for VyOS image build are installed") +checker = util.DependencyChecker(deps) -missing_packages = [] - -print("Checking if packages required for VyOS VM image build are installed") - -for p in required_packages: - if not is_installed(p): - missing_packages.append(p) - -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") - -if find_executable("packer"): - print("Your system has Packer.") +missing = checker.get_missing_dependencies() +if not missing: + print("All dependencies are installed") + sys.exit(0) else: - print("Your system does not have Packer.") - print("Please install Packer from https://www.packer.io/downloads.html.") + 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/util.py b/scripts/util.py index 00377672..7cc33364 100644 --- a/scripts/util.py +++ b/scripts/util.py @@ -19,6 +19,7 @@ import sys import os +from distutils.spawn import find_executable import defaults @@ -27,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'])) -- cgit v1.2.3 From 01083886e1e861378ce16195c9ad76c1d5ce3e4a Mon Sep 17 00:00:00 2001 From: Yuya Kusakabe Date: Mon, 7 Mar 2016 23:47:39 +0900 Subject: Add product section to VMware OVF (ref T14). --- scripts/build-vmware-ovf | 8 ++++++-- scripts/check-vm-build-env | 2 +- scripts/template.ovf | 8 +++++++- 3 files changed, 14 insertions(+), 4 deletions(-) (limited to 'scripts/check-vm-build-env') diff --git a/scripts/build-vmware-ovf b/scripts/build-vmware-ovf index f3424a03..8890ba69 100755 --- a/scripts/build-vmware-ovf +++ b/scripts/build-vmware-ovf @@ -43,8 +43,12 @@ qemu-img convert -f raw ${source_image} -O vmdk -o adapter_type=lsilogic ${tmp_v vmdk-convert ${tmp_vmdk} ${vmdk} # Generate OVF -vmdk_file_size=$(du --bytes ${vmdk} | awk '{print $1}') -cat scripts/template.ovf | sed "s/{{vmdk_file_size}}/${vmdk_file_size}/" > ${ovf} +vmdk_file_size=$(vmdk-convert -i ${vmdk} | jq .capacity) +vmdk_populated_size=$(vmdk-convert -i ${vmdk} | jq .used) +version=$(cat build/version) +cat scripts/template.ovf | sed "s/{{vmdk_file_size}}/${vmdk_file_size}/" > ${ovf} +sed -i "s/{{vmdk_populated_size}}/${vmdk_populated_size}/" ${ovf} +sed -i "s/{{version}}/${version}/" ${ovf} # Generate manifest file cd ${DST_DIR} diff --git a/scripts/check-vm-build-env b/scripts/check-vm-build-env index 47ec5922..c32f2b13 100755 --- a/scripts/check-vm-build-env +++ b/scripts/check-vm-build-env @@ -26,7 +26,7 @@ import util deps = { 'packages': [ - 'make', + 'jq', 'qemu-system-x86', 'qemu-utils' ], diff --git a/scripts/template.ovf b/scripts/template.ovf index 7e341c3e..b7c9aa32 100644 --- a/scripts/template.ovf +++ b/scripts/template.ovf @@ -5,7 +5,7 @@ Virtual disk information - + The list of logical networks @@ -111,5 +111,11 @@ + + VyOS is a Linux-based network operating system that provides software-based network routing, firewall, and VPN functionality. + VyOS + VyOS maintainers and contributors + {{version}} + -- cgit v1.2.3 From ea48b7bd747df4ae5c8ee64c72cdc67e31ddcd5a Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Wed, 25 Jan 2017 17:01:16 -0500 Subject: Switch all build scripts to python3. Since we only support jessie as build host, and jessie knowingly does have python3 (although not by default), we don't really need to worry about being both 2 and 3 compatible. --- README.md | 2 +- scripts/build-config | 3 ++- scripts/check-build-env | 4 ++-- scripts/check-config | 2 +- scripts/check-vm-build-env | 2 +- scripts/live-build-config | 2 +- scripts/make-version-file | 4 ++-- scripts/pbuilder-setup | 3 +-- scripts/query-json | 5 +++-- 9 files changed, 14 insertions(+), 13 deletions(-) (limited to 'scripts/check-vm-build-env') diff --git a/README.md b/README.md index 11edb5fb..0d6e53c2 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ There are several directories with their own purpose: To build a VyOS image, you need a machine that runs Debian Jessie. Other build hosts are not supported. -Several packages are required for building the ISO and all packages, namely live-build, pbuilder, python-pystache and devscripts. +Several packages are required for building the ISO and all packages, namely python3, live-build, pbuilder, python3-pystache and devscripts. Individual packages may have other build dependencies. If some packages are missing, build scripts will tell you. ## Building the ISO image diff --git a/scripts/build-config b/scripts/build-config index d273717f..9ea92e1f 100755 --- a/scripts/build-config +++ b/scripts/build-config @@ -1,4 +1,5 @@ -#!/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 diff --git a/scripts/check-build-env b/scripts/check-build-env index 6dcf885b..7f02c02a 100755 --- a/scripts/check-build-env +++ b/scripts/check-build-env @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Copyright (C) 2015 VyOS maintainers and contributors # @@ -32,7 +32,7 @@ deps = { 'live-build', 'pbuilder', 'devscripts', - 'python-pystache' + 'python3-pystache' ], 'binaries': [] } diff --git a/scripts/check-config b/scripts/check-config index 55d5467a..d2236619 100755 --- a/scripts/check-config +++ b/scripts/check-config @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Copyright (C) 2015 VyOS maintainers and contributors # diff --git a/scripts/check-vm-build-env b/scripts/check-vm-build-env index c32f2b13..8efab848 100755 --- a/scripts/check-vm-build-env +++ b/scripts/check-vm-build-env @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Copyright (C) 2016 VyOS maintainers and contributors # diff --git a/scripts/live-build-config b/scripts/live-build-config index cb9e84dc..2e2d4704 100755 --- a/scripts/live-build-config +++ b/scripts/live-build-config @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Copyright (C) 2015 VyOS maintainers and contributors # diff --git a/scripts/make-version-file b/scripts/make-version-file index 6c597090..3bb33319 100755 --- a/scripts/make-version-file +++ b/scripts/make-version-file @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/python3 +# # Copyright (C) 2016 VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify @@ -19,7 +20,6 @@ # that is included in the image and used by 'show version' command # and install/upgrade scripts. -from __future__ import print_function import os import datetime import json diff --git a/scripts/pbuilder-setup b/scripts/pbuilder-setup index fbd49a4f..a89348b8 100755 --- a/scripts/pbuilder-setup +++ b/scripts/pbuilder-setup @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Copyright (C) 2015 VyOS maintainers and contributors # @@ -50,4 +50,3 @@ result = os.system(pbuilder_create_command) if result > 0: print("pbuilder environment bootstrap failed") sys.exit(1) - diff --git a/scripts/query-json b/scripts/query-json index 23e64ef7..2f1ea32f 100755 --- a/scripts/query-json +++ b/scripts/query-json @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/python3 +# # Copyright (C) 2016 VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify @@ -14,7 +15,7 @@ # along with this program. If not, see . # # File: query-config -# Purpose: Extracts field values a flat JSON file, +# 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!) -- cgit v1.2.3