#!/usr/bin/env sh # Set up Rails app. Run this script immediately after cloning the codebase. # Exit if any command fails set -e YELLOW='\033[0;33m' RED='\033[0;31m' NO_COLOR='\033[0m' RUBY_VERSION=$(cat .ruby-version) NODE_VERSION=$(cat .node-version) POSTGRESQL_VERSION='9.5' DB_USER='ofn' DB_PASSWORD='f00d' # Check ruby version if ! ruby --version | grep $RUBY_VERSION > /dev/null; then printf "${RED}Open Food Network requires ruby ${RUBY_VERSION}${NO_COLOR}. Have a look at: https://github.com/rbenv/rbenv\n" exit 1 fi # Check node version if ! node --version | grep $NODE_VERSION > /dev/null; then printf "${RED}Open Food Network requires node ${NODE_VERSION}${NO_COLOR}. Have a look at: https://github.com/nodenv/nodenv\n" fi # Check postgresql version if ! psql -V | grep $POSTGRESQL_VERSION > /dev/null; then printf "${RED}Open Food Network requires postgresql ${POSTGRESQL_VERSION}${NO_COLOR}\n" exit 1 fi # Set up Ruby dependencies via Bundler if ! command -v bundle > /dev/null; then gem install bundler fi # Install all dependencies bundle check || bundle install npm install # Set up configurable environment variables if [ ! -f config/application.yml ]; then cp config/application.yml.example config/application.yml printf "${YELLOW}Copied config/application.yml Make sure to fill it with the appropriate configuration values.\n\n${NO_COLOR}" fi # Create the development database user if ! psql -c '\du' -t | grep $DB_USER > /dev/null; then psql -c "CREATE USER ${DB_USER} WITH SUPERUSER PASSWORD '${DB_PASSWORD}';" fi # Set up the database for both development and test # Confirming the default user and password Spree prompts printf '\n\n' | bundle exec rake db:setup db:test:prepare printf '\n' # Load some default data for your environment bundle exec rake openfoodnetwork:dev:load_sample_data printf '\n' printf "${YELLOW}WELCOME TO OPEN FOOD NETWORK!\n" printf '\n' printf "To login as Spree default user, use:" printf '\n' printf '\n' printf ' email: spree@example.com\n' printf " password: spree123\n${NO_COLOR}"