3 # DO NOT EDIT - This file is being maintained by Chef
8 knife="/opt/chef/embedded/bin/knife"
10 while read oldrev newrev refname
12 if [[ "$refname" = "refs/heads/master" ]]
14 cd /var/lib/chef/<%= @repository %>
16 rm -f cookbooks/*/metadata.json(N)
18 git pull --rebase --quiet
20 oldrev=$(git merge-base $oldrev $newrev)
22 for change in "${(f)$(git diff --name-status $oldrev..$newrev)}"
27 if [[ $file == roles/*.rb ]]
30 A|M) $knife role from file "${file}";;
31 D) $knife role delete -y "${file:t:r}";;
33 elif [[ $file == data_bags/*/*.json ]]
37 $knife data bag create "${file:h:t}"
38 $knife data bag from file "${file:h:t}" "${file:t}";;
40 $knife data bag delete -y "${file:h:t}" "${file:t:r}";;
42 elif [[ $file == cookbooks/* ]]
44 cookbook="${${file#[^/]*/}%%/*}"
46 if [[ -d "cookbooks/${cookbook}" ]]
48 updated_cookbooks+=("$cookbook")
50 deleted_cookbooks+=("$cookbook")
55 if [[ -n "$updated_cookbooks" ]]
57 $knife cookbook upload "${(ou)updated_cookbooks[@]}"
60 if [[ -n "$deleted_cookbooks" ]]
62 for cookbook in "${(ou)deleted_cookbooks[@]}"
64 $knife cookbook delete -y "$cookbook"