#
# This recipe copies the current Chef logic inside the box,
# so that it can be executed by the server without the need to
# checkout Chef code again.
# The following items are copied over (by default, in /etc/chef):
#
# 1. cookbooks used by Packer
# 2. databags used by Packer
#
# Chef is installed by Omnibus cookbook (check attributes/chef-client.rb
# for Chef version being installed)
#

cookbook_path = node['chef_client']['cookbook_path']
source_cookbook_path = node['chef_client']['source_cookbook_path']
if source_cookbook_path
  directory cookbook_path do
    action :create
  end
  execute "create-#{cookbook_path}" do
    command "rm -rf #{cookbook_path} ; cp -rf #{source_cookbook_path} #{cookbook_path}"
    # Force override
    # not_if "test -d #{cookbook_path}"
  end
end

data_bag_path = node['chef_client']['data_bag_path']
source_data_bag_path = node['chef_client']['source_data_bag_path']
if source_data_bag_path
  directory data_bag_path do
    action :create
  end
  execute "create-#{data_bag_path}" do
    command "rm -rf #{data_bag_path} ; cp -rf #{source_data_bag_path} #{data_bag_path} ; chmod -R 700 #{data_bag_path}"
    # Force override
    # not_if "test -d #{data_bag_path}"
  end
end
