Created
December 6, 2011 12:24
-
-
Save octplane/1438026 to your computer and use it in GitHub Desktop.
Upload changes cookbook / roles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
COOKBOOKS_FOLDER=cookbooks | |
[ -d .git ] && { | |
git fetch | |
if [ -f .git/latest_changes ]; then | |
SRC="$(cat .git/latest_changes).." | |
else | |
SRC="" | |
fi | |
B=$(git branch | grep "\*" | awk '{print $2}') | |
echo "Working on ${SRC}origin/$B" | |
DIFF=$(git diff ${SRC}origin/$B --name-only) | |
git pull | |
for role in $(echo "$DIFF" | grep roles | grep ".rb"); do | |
if [ -f roles/$roles ]; then | |
knife role from file $role | |
fi | |
# No deletion. | |
done | |
for cb in $(echo "$DIFF" | grep $COOKBOOKS_FOLDER | cut -d'/' -f2 | sort | uniq); do | |
if [ -d $COOKBOOKS_FOLDER/$cb ]; then | |
knife cookbook upload $cb | |
else | |
knife cookbook delete $cb -y | |
fi | |
done | |
# commit transaction | |
git show --format=%H | head -1 > .git/latest_changes | |
} || { | |
echo "Hope you have synchronized.." | |
knife cookbook upload -a | |
for ro in `ls roles/*.rb`; do | |
knife role from file $ro | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment