mezuro/prezento

View on GitHub
bin/setup

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby
require 'pathname'
require 'colorize'

def run(command)
  system(command)
  unless $?.exitstatus.zero?
    puts "Command #{command} exited with nonzero status".red
    exit 1
  end
end

# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../',  __FILE__)

Dir.chdir APP_ROOT do
  # This script is a starting point to setup your application.
  # Add necessary setup steps to this file:

  puts "== Installing dependencies ==".green
  run "gem install bundler --conservative"
  run "bundle check || bundle install"

  puts "\n== Copying sample files ==".green
  unless File.exist?("config/database.yml")
    run "cp config/database.yml.sample config/database.yml"
    run "cp features/support/kalibro_cucumber_helpers.yml.sample features/support/kalibro_cucumber_helpers.yml"
    run "cp config/kalibro.yml.sample config/kalibro.yml"
  end

  puts "\n== Preparing database ==".green
  puts "\n== Create database ==".yellow
  run "bin/rake db:create"
  puts "\n== Run migrations ==".yellow
  run "bin/rake db:migrate"
  puts "\n== Run seeds (may fail if the Kalibro Configurations Service is not up and running) ==".yellow
  run "bin/rake db:seed"

  puts "\n== Removing old logs and tempfiles ==".green
  run 'bin/rake log:clear'
  run 'bin/rake tmp:clear'

  puts "\n== Creating tempfiles  =="
  run 'bin/rake tmp:create'

  puts "\n== Restarting application server ==".green
  run "touch tmp/restart.txt"
end