Add initial drafts of the build scripts.

This commit is contained in:
Daniil Baturin 2015-12-17 01:25:46 -05:00
parent 27fa086f07
commit 86c6a4bdf2
6 changed files with 149 additions and 0 deletions

46
scripts/build-config Executable file
View File

@ -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)

35
scripts/check-build-env Executable file
View File

@ -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)

14
scripts/check-config Executable file
View File

@ -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)

4
scripts/defaults.py Normal file
View File

@ -0,0 +1,4 @@
import os
BUILD_DIR = 'build'
BUILD_CONFIG = os.path.join(BUILD_DIR, 'build-config.json')

40
scripts/live-build-config Executable file
View File

@ -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)

10
scripts/util.py Normal file
View File

@ -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)