Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Automatically configure all project dependencies based on Rails framework.
#!/bin/bash
echo "This is a script to try automatically configure all project dependencies basid on Rails framework."
# exit on the first error
set -e
echo "Check Ruby version"
required_ruby_version=$(cat .ruby-version)
current_ruby_version=`/usr/bin/ruby -e 'puts RUBY_VERSION'`
if [ "$required_ruby_version" != "$current_ruby_version" ]; then
echo "This project uses Ruby version $required_ruby_version, try to checkout to it"
rvm use $required_ruby_version
fi
echo "Enter master.key, the key without spaces and other characters. If you don't have a key, ask the owner for one.[Ctrl+c - for exit]"
read master_key
echo "$master_key" >> config/master.key
echo "Check Rails version"
rails_version=`rails --version`
if [ "$rails_version" != "Rails 5.2.0" ]; then
echo "You current Rails version $rails_version, but needed Rails 5.2.0 - please install this version"
exit
fi
echo "Install bundler 2.1.4 for installing all ruby gems"
gem install bundler:2.1.4
echo "Setup all gems from Gemfile"
bundler install
echo "Setup env variables"
cp .env.example .env
echo "Have you created a new database user and want to enter his username and password?[yes/no]. If no it will be setup with default user and password"
read setup_database
if [ $setup_database == "yes" ]; then
echo "User name:"
read user_name
echo "Password for user $user_name:"
read password
sed -i "s#DATABASE_USERNAME=postgres#DATABASE_USERNAME=$user_name#g" .env
sed -i "s#DATABASE_PASSWORD=postgres#DATABASE_PASSWORD=$password#g" .env
fi
echo "Setup database.yml configuration"
cp config/database.yml.example config/database.yml
echo "Setup project database"
rails db:create
rails db:migrate
rails db:seed
echo "Setup all JavaScript libraries using yarn"
yarn
echo "Do you want to run all spec tests?[yes/no]"
read run_rspec
if [ $run_rspec == "yes" ]; then
rspec
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment