[buildout]
extends =
  buildout.hash.cfg
  ../../stack/slapos.cfg
  ../../stack/monitor/buildout.cfg
  ../../component/logrotate/buildout.cfg
  ../../component/nghttp2/buildout.cfg

parts +=
  template
  slapos-cookbook
  ltelogs.jinja2.sh
# copy all configs by default
  mme.jinja2.cfg
  ims.jinja2.cfg
  enb.jinja2.cfg
  gnb.jinja2.cfg
  ue_db.jinja2.cfg
# sdr driver is dependent on ENB thus should be added explicitely by software.cfg
  sdr-driver
  lteenb-cap-sys-nice
  lteenb-avx2-cap-sys-nice
# unimplemented parts - the http monitor and better log handling using logrotate
#  apache-php
#  logrotate

[template]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/${:filename}
output = ${buildout:directory}/template.cfg
mode = 0644

[download-base]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/${:_update_hash_filename_}

[template-lte-enb-epc]
<= download-base

[template-lte-gnb-epc]
<= download-base

[template-lte-enb]
<= download-base

[template-lte-gnb]
<= download-base

[template-lte-epc]
<= download-base

[sdr-busy-promise]
<= download-base

[interface-up-promise]
<= download-base

[amarisoft]
recipe = slapos.recipe.build
path = /opt/amarisoft/lte
init = 
  import os
  options['lte-version'] = os.readlink(options["path"])[:-1]

[copy-to-instance]
recipe  = slapos.recipe.build:download
url     = ${:_profile_base_location_}/${:_buildout_section_name_}

[copy-config-to-instance]
recipe  = slapos.recipe.build:download
url     = ${:_profile_base_location_}/config/${:_buildout_section_name_}

[unpack-to-instance]
recipe = slapos.recipe.build:download-unpacked
url = ${amarisoft:path}/lte${:_buildout_section_name_}-linux-${amarisoft:lte-version}.tar.gz
destination = ${buildout:directory}/${:_buildout_section_name_}
strip-top-level-dir = true

[enb.jinja2.cfg]
<= copy-config-to-instance
filename = enb.jinja2.cfg
[gnb.jinja2.cfg]
<= copy-config-to-instance
filename = gnb.jinja2.cfg
[ltelogs.jinja2.sh]
<= copy-to-instance
filename = ltelogs.jinja2.sh
[ue_db.jinja2.cfg]
<= copy-config-to-instance
filename = ue_db.jinja2.cfg
[mme.jinja2.cfg]
<= copy-config-to-instance
filename = mme.jinja2.cfg
[ims.jinja2.cfg]
<= copy-config-to-instance
filename = ims.jinja2.cfg

[sdr]
<= unpack-to-instance
url = ${amarisoft:path}/trx_${:_buildout_section_name_}-linux-${amarisoft:lte-version}.tar.gz
destination = ${enb:destination}/x86_64
md5sum = ${trx_sdr-linux:md5sum}

[sdr-driver]
# move trx_sdr.so next to lteenb binary
recipe = plone.recipe.command
command = cp -p ${sdr:destination}/trx_sdr.so ${enb:destination}

[enb]
<= unpack-to-instance
md5sum = ${lteenb-linux:md5sum}
[mme]
<= unpack-to-instance
md5sum = ${ltemme-linux:md5sum}

[lteenb-linux]
filename = ${amarisoft:lte-version}/lteenb-linux-${amarisoft:lte-version}.tar.gz
md5sum = 842b1526073472a30cb0b286d3b1528c
[ltemme-linux]
filename = ${amarisoft:lte-version}/ltemme-linux-${amarisoft:lte-version}.tar.gz
md5sum = 9d7917f90c7c7b2a8ba624d874595351
[ltewww-linux]
filename = ${amarisoft:lte-version}/ltewww-linux-${amarisoft:lte-version}.tar.gz
md5sum = 416b6167f70b12910fbbb9293038554c
[trx_sdr-linux]
filename = ${amarisoft:lte-version}/trx_sdr-linux-${amarisoft:lte-version}.tar.gz
md5sum = e6960e3460f1a32c2436f36b2082995d

[base-lteenb-cap-sys-nice]
recipe = plone.recipe.command
command =
  getcap ${amarisoft:path}/${:binary} | grep cap_sys_nice+ep && exit 0;
  # Make a copy or restore the copy, as patchelf will irreversibly change the md5sum
  stat ${enb:destination}/${:binary}-unpriviledged ||
    cp ${enb:destination}/${:binary} ${enb:destination}/${:binary}-unpriviledged &&
    cp ${enb:destination}/${:binary}-unpriviledged ${enb:destination}/${:binary}
  # ORS are pre-configured to have sudo allow slapsoft to run give-cap-sys-nice-lteenb script
  # with root permissions
  sudo -n ${amarisoft:path}/../give-cap-sys-nice-lteenb ${enb:destination}/${:binary} || true;
update-command = ${:command}

[lteenb-avx2-cap-sys-nice]
<= base-lteenb-cap-sys-nice
binary=lteenb

[lteenb-cap-sys-nice]
<= base-lteenb-cap-sys-nice
binary=lteenb-avx2
