setup 1.26 KB
Newer Older
Valery Sizov's avatar
Valery Sizov committed
1
#!/usr/bin/env ruby
2
3
4
5
6
7

def rails5?
  %w[1 true].include?(ENV["RAILS5"])
end

require "pathname"
Valery Sizov's avatar
Valery Sizov committed
8
9

# path to your application root.
10
11
12
13
14
15
16
APP_ROOT = Pathname.new File.expand_path("../../", __FILE__)

if rails5?
  def system!(*args)
    system(*args) || abort("\n== Command #{args} failed ==")
  end
end
Valery Sizov's avatar
Valery Sizov committed
17
18

Dir.chdir APP_ROOT do
19
  # This script is a starting point to set up your application.
Valery Sizov's avatar
Valery Sizov committed
20
21
22
  # Add necessary setup steps to this file:

  puts "== Installing dependencies =="
23
24
25
26
27
28
29
30

  if rails5?
    system! "gem install bundler --conservative"
    system("bundle check") || system!("bundle install")
  else
    system "gem install bundler --conservative"
    system "bundle check || bundle install"
  end
Valery Sizov's avatar
Valery Sizov committed
31
32
33

  # puts "\n== Copying sample files =="
  # unless File.exist?("config/database.yml")
34
  #   cp "config/database.yml.sample", "config/database.yml"
Valery Sizov's avatar
Valery Sizov committed
35
36
37
  # end

  puts "\n== Preparing database =="
38
39
40
41
42
43

  if rails5?
    system! "bin/rails db:setup"
  else
    system "bin/rake db:reset"
  end
Valery Sizov's avatar
Valery Sizov committed
44
45

  puts "\n== Removing old logs and tempfiles =="
46
47
48
49
50
51
52

  if rails5?
    system! "bin/rails log:clear tmp:clear"
  else
    system "rm -f log/*"
    system "rm -rf tmp/cache"
  end
Valery Sizov's avatar
Valery Sizov committed
53
54

  puts "\n== Restarting application server =="
55
56
57
58
59
60

  if rails5?
    system! "bin/rails restart"
  else
    system "touch tmp/restart.txt"
  end
Valery Sizov's avatar
Valery Sizov committed
61
end