Skip to content

Instantly share code, notes, and snippets.

@clifferson
Forked from capoferro/knife-config
Created November 10, 2012 04:11
Show Gist options
  • Save clifferson/4049857 to your computer and use it in GitHub Desktop.
Save clifferson/4049857 to your computer and use it in GitHub Desktop.
Shell script to swap knife configs
#!/bin/sh
die () {
echo >&2 "$@"
exit 1
}
available_configs () {
echo "Available configs:"
ls -A ~ | grep .chef- | sed 's/.chef-//'
}
if [ ! "$#" == 1 ]
then
echo "Usage: knife-config CHEF_SERVER"
available_configs
exit 0
fi
if [ ! -d ~/.chef-$1 ]
then
available_configs
die "~/.chef-$1 does not exist or is not a directory."
fi
if [ ! -L ~/.chef ]
then
if [ -a ~/.chef ]
then
die "~/.chef is not a symlink."
fi
fi
rm -f ~/.chef
if [ -a ~/.chef ]
then
die "~/.chef not successfully deleted"
fi
if [ ! -a ~/.chef ]
then
echo "~/.chef symlinked to ~/.chef-$1"
ln -s ~/.chef-$1 ~/.chef
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment