Skip to content

Instantly share code, notes, and snippets.

@postwait
Created May 31, 2013 15:36
Show Gist options
  • Select an option

  • Save postwait/5685823 to your computer and use it in GitHub Desktop.

Select an option

Save postwait/5685823 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Install a full Opscode Client
#
PROGNAME=`basename $0`
INSTALLER_DIR=/opt/chef
CONFIG_DIR=/etc/chef
USAGE="usage: $0 [-v validation_key] ([-o organization] || [-u url])"
error_exit()
{
echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2
exit 1
}
validation_key=
organization=
chef_url=
while getopts o:u:v: opt
do
case "$opt" in
v) validation_key="${OPTARG}";;
o) organization="${OPTARG}"; chef_url="https://api.opscode.com/organizations/${OPTARG}";;
u) chef_url="${OPTARG}";;
\?) # unknown flag
echo >&2 ${USAGE}
exit 1;;
esac
done
shift `expr ${OPTIND} - 1`
if [ "" != "$chef_url" ]; then
mkdir -p ${CONFIG_DIR} || error_exit "Cannot create ${CONFIG_DIR}!"
(
cat <<'EOP'
log_level :info
log_location STDOUT
EOP
) > ${CONFIG_DIR}/client.rb
if [ "" != "$chef_url" ]; then
echo "chef_server_url '${chef_url}'" >> ${CONFIG_DIR}/client.rb
fi
if [ "" != "$organization" ]; then
echo "validation_client_name '${organization}-validator'" >> ${CONFIG_DIR}/client.rb
fi
chmod 644 ${CONFIG_DIR}/client.rb
fi
if [ "" != "$validation_key" ]; then
cp ${validation_key} ${CONFIG_DIR}/validation.pem || error_exit "Cannot copy the validation key!"
chmod 600 ${CONFIG_DIR}/validation.pem
fi
# rm -f before ln -sf is required for solaris 9
rm -f /usr/bin/chef-client
rm -f /usr/bin/chef-solo
rm -f /usr/bin/knife
rm -f /usr/bin/shef
rm -f /usr/bin/ohai
ln -sf $INSTALLER_DIR/bin/chef-client /usr/bin || error_exit "Cannot link chef-client to /usr/bin"
ln -sf $INSTALLER_DIR/bin/chef-solo /usr/bin || error_exit "Cannot link chef-solo to /usr/bin"
ln -sf $INSTALLER_DIR/bin/knife /usr/bin || error_exit "Cannot link knife to /usr/bin"
ln -sf $INSTALLER_DIR/bin/shef /usr/bin || error_exit "Cannot link shef to /usr/bin"
ln -sf $INSTALLER_DIR/bin/ohai /usr/bin || error_exit "Cannot link ohai to /usr/bin"
echo "Thank you for installing Chef!"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment