#!/usr/bin/env bash

# Requirements
# - Knife binary installed
# - Berks plugin installed
# - This script should be called from the base directory of the cookbook in question.

set -ex

COOKBOOK_NAME=$(basename $(pwd))
KNIFE_BINARY=$(/usr/bin/which knife)
BERKS_BINARY=$(/usr/bin/which berks)

set +x

if [ -x ${KNIFE_BINARY} ] && [ -x ${BERKS_BINARY} ]; then
  printf '%s\n' "Berks and Knife binaries found. Continuing..."
else
  printf '%s\n' "Berks or Knife binaries not found or executable." && exit 1
fi

yes | ${BERKS_BINARY} cookbook ${COOKBOOK_NAME}
mv ${COOKBOOK_NAME}/* .
rm -rf ${COOKBOOK_NAME}
