diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rwxr-xr-x | scripts/build-config | 18 | ||||
| -rw-r--r-- | scripts/defaults.py | 3 | ||||
| -rwxr-xr-x | scripts/make-version-file | 66 | 
4 files changed, 87 insertions, 2 deletions
| @@ -15,6 +15,8 @@ prepare:  	@scripts/live-build-config  	cp -r data/live-build-config/* build/config/ +	@scripts/make-version-file +  .PHONY: iso  .ONESHELL:  iso: prepare diff --git a/scripts/build-config b/scripts/build-config index d0d2fdac..685d79f2 100755 --- a/scripts/build-config +++ b/scripts/build-config @@ -49,13 +49,19 @@ 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),     'debian-mirror': ('Debian repository mirror for ISO build', lambda: defaults.DEBIAN_MIRROR, None), -   'pbuilder-debian-mirror': ('Debian repository mirror for pbuilder env bootstrap', lambda: defaults.DEBIAN_MIRROR, None) +   'pbuilder-debian-mirror': ('Debian repository mirror for pbuilder env bootstrap', lambda: defaults.DEBIAN_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())  args = vars(parser.parse_args()) @@ -75,6 +81,14 @@ 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 diff --git a/scripts/defaults.py b/scripts/defaults.py index beef4a7a..b9a3f255 100644 --- a/scripts/defaults.py +++ b/scripts/defaults.py @@ -28,3 +28,6 @@ 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') diff --git a/scripts/make-version-file b/scripts/make-version-file new file mode 100755 index 00000000..fcc399f8 --- /dev/null +++ b/scripts/make-version-file @@ -0,0 +1,66 @@ +#!/usr/bin/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 <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. + +from __future__ import print_function +import os +import datetime +import json +import uuid + +import defaults +import util + +util.check_build_config() +with open(defaults.BUILD_CONFIG, 'r') as f: +     build_config = json.load(f) + + +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()) + +if build_config['build_type'] == 'development': +    version = "999.{0}".format(build_timestamp) +else: +    version = build_config['version'] + +version_data = { +    'version': version, +    'built_by': build_config['build_by'], +    'built_on': build_date, +    'build_id': build_id +} + + +with open(os.path.join(defaults.CHROOT_INCLUDES_DIR, 'opt/vyatta/etc/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) | 
