-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathsetup
More file actions
executable file
·73 lines (55 loc) · 2.64 KB
/
Copy pathsetup
File metadata and controls
executable file
·73 lines (55 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env ruby
require 'fileutils'
include FileUtils
# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
valid_db = ARGV.length > 0 && %w[mysql postgres].include?(ARGV[0].to_s.downcase.strip)
if valid_db
db_adapter = ARGV[0].to_s.downcase.strip == 'mysql' ? 'mysql2' : 'postgresql'
chdir APP_ROOT do
# This script is a starting point to setup your application.
# Add necessary setup steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
system! 'yarn install'
puts "\n== Copying sample files =="
cp 'config/database.yml.sample', 'config/database.yml'
cp 'config/initializers/contact_us.rb.example', 'config/initializers/contact_us.rb'
cp 'config/initializers/wicked_pdf.rb.example', 'config/initializers/wicked_pdf.rb'
cp ".env.#{db_adapter}", '.env'
puts "\n== Preparing credentials file =="
system!("EDITOR=\"sh -c 'echo \\\"$(cat config/credentials.yml.#{db_adapter})\\\" > \\\"\\\$1\\\"' --\" bin/rails credentials:edit")
# Set the editor based on the platform
ENV['EDITOR'] = Gem.win_platform? ? 'code --wait' : 'vim'
puts "\n== Opening .env in editor ... please update as needed =="
puts " In particular make sure your DB settings are correct."
sleep(3)
system! '$EDITOR .env'
puts "\n== Opening credentials editor ... please update as needed =="
puts " In particular make sure your DB settings are correct."
sleep(3)
system! 'bin/rails credentials:edit'
puts "\n== Preparing database =="
system! 'bin/rails db:setup'
puts "\n== Populating License table =="
system! 'bin/rails external_api:load_spdx_licenses'
puts "\n== Populating Metadata Standards table =="
system! 'bin/rails external_api:load_rdamsc_standards'
puts "\n== Populating Research Domains table =="
system! 'bin/rails external_api:add_field_of_science_to_research_domains'
puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
system! 'bin/rails restart'
puts "\n== !!We highly recommend that you populate the Repositories table, but this can take"
puts "in excess of 10 minutes so we do not run it as part of this setup!!"
puts " To run it on your own: `bin/rails external_api:load_re3data_repos`"
end
else
puts "\n== You MUST specify the type of DB you would like to use. Either mysql or postgres =="
puts "== For example: `ruby bin/setup postgres` =="
end