]> git.openstreetmap.org Git - chef.git/blob - cookbooks/chef/templates/default/post-receive.erb
Remvoe cleanup code
[chef.git] / cookbooks / chef / templates / default / post-receive.erb
1 #!/bin/zsh
2
3 # DO NOT EDIT - This file is being maintained by Chef
4
5 umask 0002
6 unset GIT_DIR
7
8 while read oldrev newrev refname
9 do
10   if [[ "$refname" = "refs/heads/master" ]]
11   then
12     cd /var/lib/chef/<%= @repository %>
13
14     rm -f cookbooks/*/metadata.json(N)
15
16     git pull --rebase --quiet
17
18     oldrev=$(git merge-base $oldrev $newrev)
19
20     for change in "${(f)$(git diff --name-status $oldrev..$newrev)}"
21     do
22       action=${change[1]}
23       file=${change[3,-1]}
24
25       if [[ $file == roles/*.rb ]]
26       then
27         case "$action" in
28           A|M) knife role from file "${file}";;
29           D) knife role delete -y "${file:t:r}";;
30         esac
31       elif [[ $file == data_bags/*/*.json ]]
32       then
33         case "$action" in
34           A|M) 
35             knife data bag create "${file:h:t}"
36             knife data bag from file "${file:h:t}" "${file:t}";;
37           D)
38             knife data bag delete -y "${file:h:t}" "${file:t:r}";;
39         esac
40       elif [[ $file == cookbooks/* ]]
41       then
42         cookbook="${${file#[^/]*/}%%/*}"
43     
44         if [[ -d "cookbooks/${cookbook}" ]]
45         then
46           updated_cookbooks+=("$cookbook")
47         else
48           deleted_cookbooks+=("$cookbook")
49         fi
50       fi
51     done
52
53     if [[ -n "$updated_cookbooks" ]]
54     then
55       knife cookbook upload "${(ou)updated_cookbooks[@]}"
56     fi
57
58     if [[ -n "$deleted_cookbooks" ]]
59     then
60       for cookbook in "${(ou)deleted_cookbooks[@]}"
61       do
62         knife cookbook delete -y "$cookbook"
63       done
64     fi
65   fi
66 done