#!/usr/bin/env bash

usage()
{
  echo "Usage: coreos-bblayers-envsub key value"
  echo "Replace ##key## with value inside ${BBLAYERSCONF}"
  exit 0
}

if [ -z "${BUILDDIR}" ]; then
    echo "BUILDDIR not set. Are you in a bitbake environment?"
    exit 2
fi

BBLAYERSCONF="${BUILDDIR}/conf/bblayers.conf"

if [[ $1 =~ ^(-h|--help)$ ]]; then
    usage
fi

# Put the absolute path to the layers in bblayers.conf
# Replace ##ARG1## with ARG2
sed -i -e "s|##$1##|$2|g" "$BBLAYERSCONF"
