Skip to content

Instantly share code, notes, and snippets.

@capoferro
Last active October 7, 2015 09:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save capoferro/3146979 to your computer and use it in GitHub Desktop.
Save capoferro/3146979 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
@logankoester
Copy link

Related: https://github.com/trobrock/chefvm (alternative solution)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment