-
-
Save clifferson/4049857 to your computer and use it in GitHub Desktop.
Shell script to swap knife configs
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 | |
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