Created
May 5, 2015 16:19
-
-
Save durrantm/050bdbeb4facbb7d4730 to your computer and use it in GitHub Desktop.
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
check_rvm_rubies_installed() { | |
rvm list > $BASE/local_ruby_versions.txt | |
#TODO local versions="" | |
for ruby in "${ruby_versions[@]}" | |
do | |
versions=$versions"${ruby##*::} " | |
done | |
unique_versions=`echo $versions | tr ' ' '\n' | sort -u | tr '\n' ' '` | |
for one_version in $unique_versions | |
do | |
if grep -q $one_version $BASE/local_ruby_versions.txt | |
then echo "=== ruby version $one_version confirmed as present on this machine" | |
else | |
rvm list | |
echo "*** EXITING install *** - not all required ruby versions are present in RVM" | |
echo "Please install RVM ruby version: $one_version and then re-run this program" | |
exit | |
fi | |
done | |
echo "=== All required Ruby Versions confirmed as present locally" | |
rm -f $BASE/local_ruby_versions.txt | |
} | |
create_repository_area() { | |
echo "=== Creating repositories directory (errors are ok if it already exists)" | |
mkdir "$REPOSITORIES_LOCATION" | |
} | |
clone_and_update_repositories() { | |
echo "=== Cloning repositories (errors are ok if they already exist)..." | |
echo "initial pwd=" $PWD | |
for repo in "${repositories_and_ruby_versions[@]}" | |
do | |
repo="${repo%%::*}" | |
cd $REPOSITORIES_LOCATION | |
if [[ -e $REPOSITORIES_LOCATION/$repo/.git ]]; then | |
cd $REPOSITORIES_LOCATION/$repo | |
git reset --hard origin/master | |
echo "=== Now doing git pull for $repo repositoryh" | |
git pull | |
else | |
echo "=== Now doing first time git clone for $repo repository" | |
git clone git.zipcar.com:$repo | |
fi | |
done | |
} | |
bundle_repositories() { | |
echo "=== Doing bundles..." | |
for repo in "${repositories_and_ruby_versions[@]}" | |
do | |
repo_to_bundle="${repo%%::*}" | |
echo "=== Bundling: ${repo_to_bundle}" | |
ruby_version="${repo##*::}" | |
echo "=== using ruby version: ${repo##*::}" | |
ensure_bundle $repo_to_bundle $ruby_version | |
done | |
echo "=== Bundles completed" | |
} | |
perform_migrations() { | |
echo "=== Now running doing rake db:migrate for pure rails apps..." | |
for migrate_repo in "${run_db_migrate_for[@]}" | |
do | |
cd $REPOSITORIES_LOCATION/$migrate_repo | |
rake db:migrate RAILS_ENV=test | |
done | |
} | |
determine_repositories_to_run_db_migrate() { | |
#run_db_migrate_for=('pooling-api') | |
run_db_migrate_for=('') | |
} | |
check_rvm_installed() { | |
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then | |
source "$HOME/.rvm/scripts/rvm" | |
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then | |
source "/usr/local/rvm/scripts/rvm" | |
else | |
printf "ERROR: An RVM installation was not found.\n" | |
printf "Exiting - please install RVM\n" | |
exit 1 | |
fi | |
} | |
select_ruby_version() { | |
for repo in "${repository_and_ruby_versions[@]}" | |
do | |
if [ "${repo%%::*}" == "$1" ]; then | |
rvm use "${repo##*::}" | |
fi | |
done | |
} | |
ensure_bundle() { | |
pushd $REPOSITORIES_LOCATION/$1 > /dev/null | |
select_ruby_version $1 | |
bundle --quiet || { echo "=== Bundle failed for $1" && exit ; } | |
popd > /dev/null | |
} | |
bundle_update_dependency() { | |
pushd $TOPDIR/$REPOSITORIES_LOCATION/$1 | |
select_ruby_version $1 | |
echo "=== Bundle update $2 for $1" | |
bundle update $2 --quiet || { echo "Bundle update $2 failed for $1" && exit ; } | |
popd | |
} | |
exit_on_error() { | |
if [ $? -ne 0 ]; then | |
echo "ERROR: $*" 1>&2 | |
exit 1 | |
fi | |
} | |
hide_bundle_config() { | |
if [ -f "~/.bundle/config" ]; then | |
mv ~/.bundle/config ~/.bundle/config_save | |
fi | |
} | |
create_and_cd_to_repos_area() { | |
mkdir -p $REPOSITORIES_LOCATION | |
cd $REPOSITORIES_LOCATION | |
} | |
restore_bundle_configuration() { | |
cp ~/.bundle/config_save ~/.bundle/config | |
} | |
pause_at_line() { | |
read -p "paused at line $1 enter to continue" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment