# Jinja2 template of a buildout file to create runnable scripts
#
# Received variables
# -  project_dir: location where this repository was cloned to
# -  software_dir: location where this 'instance.cfg' is gettin rendered (same as ${buildout:directory})

[buildout]
parts =
  monitor-base
  parameters
  promise-sudo-on-host
  template-full-build-script
  template-sudo-wrapper
  template-cros-sdk-wrapper
  resiliency-exclude-file

extends = {{ monitor_template }}
# standard declaration of eggs directories
eggs-directory = {{ eggs_directory }}
develop-eggs-directory = {{ develop_eggs_directory }}

#################################### Tools, sources getter ##################################

[depot-tools]
# needed for the "repo" command (to download many git repositories)
recipe = slapos.recipe.build:gitclone
repository = https://chromium.googlesource.com/chromium/tools/depot_tools.git
branch = master
git-executable = {{ git_path }}/bin/git

[customize-path]
# add depot tools directory (for cros_sdk binary among others) and git directory to the path
command =
  export PATH="${directory:wrapper_dir}":"{{ software_dir }}/bin":"{{ git_path }}/bin":"{{ curl_path }}/bin":"${depot-tools:location}":"{{thin_provisioning_tools}}/sbin":"$PATH";

[nayuos-ebuilds]
recipe = slapos.recipe.build:gitclone
repository = https://lab.nexedi.com/nexedi/nayuos-ebuilds.git
branch = master
git-executable = {{ git_path }}/bin/git

############################################################################################

[parameters]
# for use of the "parameters" XML configuration given from the
# webrunner interface
# if needed, .serialized => json (more complex structures are OK, but need another 
# jinja template for reading the content of the parameters)
recipe = slapos.cookbook:slapconfiguration
computer = ${slap_connection:computer_id}
partition = ${slap_connection:partition_id}
url = ${slap_connection:server_url}
key = ${slap_connection:key_file}
cert = ${slap_connection:cert_file}

[directory]
recipe = slapos.cookbook:mkdirectory
log = ${buildout:directory}/var/log
run = ${buildout:directory}/etc/run
backup = ${buildout:directory}/srv/backup
wrapper_dir = ${buildout:directory}/wrapper_bin
cros_location = ${buildout:directory}/parts/chromiumos
images = ${:cros_location}/images

[bin]
# dummy section to hold references to frequently used binaries
wrapper_cros_sdk=${directory:wrapper_dir}/wrapper_cros_sdk
bash=/bin/bash
sudo=/usr/bin/sudo

[promise-sudo-on-host-bin]
recipe  = slapos.cookbook:wrapper
wrapper-path = ${directory:bin}/${:_buildout_section_name_}
command-line = sudo -V

[promise-sudo-on-host]
# assert sudo is installed, as it is required to enter the chroot 'cros_sdk'
<= monitor-promise-base
module = check_command_execute
name = ${:_buildout_section_name_}.py
config-command = ${promise-sudo-on-host-bin:wrapper-path}

[template-sudo-wrapper]
recipe = slapos.recipe.template:jinja2
template = {{ project_dir }}/scripts/wrapper_sudo.in
rendered = ${directory:wrapper_dir}/sudo
md5sum = ded5a92be4e37ec32eb9d3087d3e19bd
mode = 0700
context =
  key fake_cros_sdk_path bin:wrapper_cros_sdk
  key bash_path bin:bash
  key host_sudo_path bin:sudo

[template-cros-sdk-wrapper]
recipe = slapos.recipe.template:jinja2
template = {{ project_dir }}/scripts/wrapper_cros_sdk.in
rendered = ${bin:wrapper_cros_sdk}
md5sum = 7159fe3d5b85a283733cf686c4ee0a74
mode = 0700
context =
# XXX bash path is the one from the host
  key bash_path bin:bash
  raw git_path  {{ git_path }}/bin
  raw curl_path {{ curl_path }}/bin

[template-full-build-script]
# create the rendered script in the buildout-directory/etc/run
# (use jinja for templating)
recipe = slapos.recipe.template:jinja2
template = {{ project_dir }}/scripts/cros_full_build.in
rendered = ${directory:run}/cros_full_build
#md5sum = f3b3b5408b69f752f2221d3965caf590
mode = 0700
context =
  key bash_path                         bin:bash
  key instance_log_dir                  directory:log
  key instance_dir                      buildout:directory
  key cros_location                     directory:cros_location
  key export_path_cmd                   customize-path:command
  key branch                            parameters:configuration.branch
  key boards_list                       parameters:configuration.boards
  key keep_cache                        parameters:configuration.keep_cache
  key ebuilds_dir                       nayuos-ebuilds:location
  raw scripts_dir                       {{ project_dir }}/scripts
  raw logo_dir                          {{ project_dir }}/logo
  raw wallpaper_dir                     {{ project_dir }}/wallpaper
  raw patch_dir                         {{ project_dir }}/patch
# packages to be copied from our overlay into ChromiuOS' overlay
# those packages will be marked as dependency of root filesystem
  raw nayu_dev_rootfs_packages          app-misc/nayuos-chromium-policy
# those packages will be marked as dependency of the chromium build itself
  raw nayu_dev_packages                 dev-vcs/git dev-python/flask dev-python/virtualenv sys-fs/cryptsetup

[resiliency-exclude-file]
# Generate rdiff exclude file for resiliency
recipe = collective.recipe.template
input = inline: parts/chromiumos/release*
output = ${directory:srv}/exporter.exclude