#!/bin/bash
# This script will copy the templates to the appropriate location.
# Note that the implementation relies on the detail that all elements
# share one dir inside the chroot.
set -eux
set -o pipefail

TEMPLATE_ROOT=$(os-apply-config --print-templates)
TEMPLATE_SOURCE_PREFIX=$(dirname $0)/..
mkdir -p $TEMPLATE_ROOT

for BN in os-config-applier \
          os-apply-config \
          post-os-apply-config; do
  TEMPLATE_SOURCE=${TEMPLATE_SOURCE_PREFIX}/${BN}
  if [[ -d "${TEMPLATE_SOURCE}" ]]; then
    rsync --exclude='.*.swp' -Cr $TEMPLATE_SOURCE/ $TEMPLATE_ROOT/
  fi
done
