summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/build-config46
-rwxr-xr-xscripts/check-build-env35
-rwxr-xr-xscripts/check-config14
-rw-r--r--scripts/defaults.py4
-rwxr-xr-xscripts/live-build-config40
-rw-r--r--scripts/util.py10
6 files changed, 149 insertions, 0 deletions
diff --git a/scripts/build-config b/scripts/build-config
new file mode 100755
index 00000000..7d1aa66b
--- /dev/null
+++ b/scripts/build-config
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+
+import argparse
+import re
+import sys
+import os
+import getpass
+import platform
+import json
+
+import defaults
+
+# argparse converts hyphens to underscores,
+# so for lookups in the original options hash we have to
+# convert them back
+def field_to_option(s):
+ return re.sub(r'_', '-', s)
+
+def get_default_build_by():
+ return "{user}@{host}".format(user= getpass.getuser(), host=platform.node())
+
+
+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)
+}
+
+# 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]())
+
+args = vars(parser.parse_args())
+
+# Validate options
+for k, v in args.items():
+ key = field_to_option(k)
+ func = options[key][2]
+ 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)
+
+# Save to file
+with open(defaults.BUILD_CONFIG, 'w') as f:
+ json.dump(args, f)
diff --git a/scripts/check-build-env b/scripts/check-build-env
new file mode 100755
index 00000000..11e1c66b
--- /dev/null
+++ b/scripts/check-build-env
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+
+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 = []
+
+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)
+
+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")
+ sys.exit(0)
diff --git a/scripts/check-config b/scripts/check-config
new file mode 100755
index 00000000..3949869b
--- /dev/null
+++ b/scripts/check-config
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+
+import sys
+import os
+
+import defaults
+
+
+print("Checking build configuration")
+
+if not os.path.exists(defaults.BUILD_CONFIG):
+ print("Build config does not exist")
+ print("Please run the ./configure script and try again")
+ sys.exit(1)
diff --git a/scripts/defaults.py b/scripts/defaults.py
new file mode 100644
index 00000000..96dfcc98
--- /dev/null
+++ b/scripts/defaults.py
@@ -0,0 +1,4 @@
+import os
+
+BUILD_DIR = 'build'
+BUILD_CONFIG = os.path.join(BUILD_DIR, 'build-config.json')
diff --git a/scripts/live-build-config b/scripts/live-build-config
new file mode 100755
index 00000000..59f0bbb2
--- /dev/null
+++ b/scripts/live-build-config
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+
+import sys
+import os
+import json
+
+import pystache
+
+import defaults
+import util
+
+util.check_build_config()
+
+lb_config_tmpl = """
+lb config noauto \
+ --architectures {{architecture}} \
+ --bootappend-live "boot=live components hostname=vyos username=live" \
+ --bootloader syslinux \
+ --binary-images iso-hybrid \
+ --debian-installer false \
+ --distribution jessie \
+ --iso-application "VyOS" \
+ --iso-publisher "{{build_by}}" \
+ --iso-volume "VyOS" \
+ --debootstrap-options "--variant=minbase --exclude=isc-dhcp-client,isc-dhcp-common,ifupdown" \
+ "${@}"
+"""
+
+with open(defaults.BUILD_CONFIG, 'r') as f:
+ build_config = json.load(f)
+
+lb_config_command = pystache.render(lb_config_tmpl, build_config)
+
+print("Configuring live-build")
+os.chdir(defaults.BUILD_DIR)
+
+result = os.system(lb_config_command)
+if result > 0:
+ print("live-build config failed")
+ sys.exit(1)
diff --git a/scripts/util.py b/scripts/util.py
new file mode 100644
index 00000000..740d4ccc
--- /dev/null
+++ b/scripts/util.py
@@ -0,0 +1,10 @@
+import sys
+import os
+
+import defaults
+
+def check_build_config():
+ if not os.path.exists(defaults.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)