Skip to content

Instantly share code, notes, and snippets.

@kvzb
Created April 18, 2014 13:00
Show Gist options
  • Save kvzb/11043042 to your computer and use it in GitHub Desktop.
Save kvzb/11043042 to your computer and use it in GitHub Desktop.
Quasi-generic Rails app bootstrapping script.
#!/bin/bash
bold=`tput bold`
normal=`tput sgr0`
Bold() { echo "${bold}---> $1${normal}"; }
Tab() { echo " $1"; }
Done() { Tab "Done."; }
# Target Ruby version.
local_ruby_version="1.9.3-p545"
# Required binaries to check for.
BINS=( mysqld )
# Check the presence of a .ruby-version
Bold "Checking for a .ruby-version file..."
if [ -f .ruby-version ]; then
Tab "You already have a .ruby-version file.";
else
Tab "Creating a .ruby-version file with version $local_ruby_version..."
echo $local_ruby_version > .ruby-version;
Done
fi
# Check that the correct Ruby version is in use.
Bold "Checking that you are using the correct Ruby version..."
if [[ $(ruby -v) =~ ${local_ruby_version/-/} ]]; then
Tab "You are using the correct Ruby version."
else
Tab "You are not using the correct Ruby version."
Tab "Please switch it to $local_ruby_version and run this script again."
exit 0
fi
# Check for bundler.
Bold "Checking for Bundler..."
if [[ $(bundle version) =~ ^Bundler ]]; then
Tab "You have Bundler up and running."
else
Tab "You do not have Bundler installed."
Tab "Please run 'gem install bundler' and run this script again."
exit 0
fi
# Alert & exit if a runtime dependency is missing.
Bold "Checking for missing runtime dependencies..."
for (( i=0;i<${#BINS[@]};i++)); do
bin=${BINS[${i}]}
if [ -z $(which $bin) ]; then
Tab "You do not have $bin in your PATH. It is necessary."
exit 0
else
Tab "$bin is present in your PATH."
fi
done
Tab "Runtime dependencies are all met."
Bold "Installing gem dependencies..."
bundle install
Done
# Create development env file unless it exists.
Bold "Creating a development .env file..."
if [ -f .env.development ]; then
Tab "You already have a development .env file.";
else
cp .env.default .env.development;
Done
fi
# Copy database.yml file unless it exists.
Bold "Creating a development database.yml file..."
if [ -f config/database.yml ]; then
Tab "You already have a database.yml file.";
else
cp config/database.default.yml config/database.yml;
Done
Tab "Edit it with your correct credentials then run this script again.";
exit 0;
fi
# Drop development database.
Bold "Dropping existing development database..."
rake db:drop
Done
# Create the database.
Bold "Creating the database..."
rake db:create
Done
# Load the DB schema.
Bold "Loading the database schema..."
rake db:schema:load &> /dev/null
Done
# Create demo data.
Bold "Injecting demo data in the database..."
rake data:demo &> /dev/null
Done
Bold " Finished bootstrapping application."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment