Created
May 12, 2013 01:17
-
-
Save jwilkins/5562028 to your computer and use it in GitHub Desktop.
bootstrap a ruby project w/ bundler & rbenv
This file contains hidden or 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
#!/usr/bin/env bash | |
NOW=$(date +"%Y%m%d%H%M%S") | |
echo -n "[*] bootstrapping " | |
# Export CC to explicitly set the compiler used for cexts. | |
export CC=cc | |
function abspath { | |
if [[ -d "$1" ]]; then | |
pushd "$1" >/dev/null | |
pwd | |
popd >/dev/null | |
elif [[ -e $1 ]]; then | |
pushd "$(dirname "$1")" >/dev/null | |
echo "$(pwd)/$(basename "$1")" | |
popd >/dev/null | |
else | |
echo "$1" does not exist! >&2 | |
return 127 | |
fi | |
} | |
ABSPATH=$(abspath ".") | |
echo "${ABSPATH} (@${NOW}).. " | |
GEM_HOME=${ABSPATH}/vendor/gems/ruby/1.9.1 | |
GEM_PATH=${ABSPATH}/vendor/gems/ruby/1.9.1 | |
PATH=${ABSPATH}/bin:${ABSPATH}/vendor/gems/bin:${PATH} | |
# if rbenv? | |
USING_RBENV=$(rbenv version) | |
if [[ $? == 0 ]]; then | |
echo "- Using rbenv: ${USING_RBENV}" | |
RUBY_CMD_PREFIX='rbenv exec' | |
# can run `which ruby` => grep for rbenv if rbenv exists `rbenv version` gives | |
# output, no env setting if using default ruby in rbenv, otherwise | |
# RBENV_VERSION is set | |
if ! [[ -f .rbenv-vars ]]; then | |
echo "- no .rbenv-vars, creating" | |
cat <<- EOF >> .rbenv-vars | |
GEM_HOME=${GEM_HOME} | |
GEM_PATH=${GEM_PATH} | |
PATH=${PATH} | |
EOF | |
fi | |
fi | |
# clean out any old .bundles | |
if [[ -a ${ABSPATH}/.bundle ]]; then | |
echo "- moving existing .bundle to .bundle.${NOW}" | |
mv ${ABSPATH}/.bundle ${ABSPATH}/.bundle.${NOW} | |
mkdir .bundle | |
fi | |
echo "- installing bundler" | |
${RUBY_CMD_PREFIX} gem install bundler | |
# Bundle install unless we're already up to date. | |
echo "- checking bundle" | |
if ! ${RUBY_CMD_PREFIX} bundle check > /dev/null 2>&1; then | |
echo "- running bundle install" | |
${RUBY_CMD_PREFIX} bundle install --binstubs --path vendor/gems "$@" | |
else | |
echo "- bundle ok" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment