Skip to content

Instantly share code, notes, and snippets.

@octplane
Created December 6, 2011 12:24
Show Gist options
  • Save octplane/1438026 to your computer and use it in GitHub Desktop.
Save octplane/1438026 to your computer and use it in GitHub Desktop.
Upload changes cookbook / roles
#!/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