forked from refinery/refinerycms
/
refinery
77 lines (68 loc) · 3.41 KB
/
refinery
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
74
75
76
77
#!/usr/bin/env ruby
require 'fileutils'
REFINERY_ROOT = File.expand_path(File.dirname(__FILE__) << "/..")
unless (app_path = ARGV.shift).nil? or app_path.length == 0
RAILS_ROOT = app_path =~ /(\.(\/)?)/ ? Dir.getwd : app_path
if File.exists? RAILS_ROOT
if ARGV.include?("--force")
# remove the contents of the current directory
Dir[File.join(RAILS_ROOT, "*")].each {|dir| FileUtils::rm_rf(dir, :secure => true) }
else
puts "The path you specified already exists. If you want to override this directory (i.e. delete all the current contents) run this again with --force"
end
end
unless File.exists? RAILS_ROOT and !ARGV.include?("--force")
# make the application path directory
FileUtils::makedirs RAILS_ROOT
# copy in all of the relevant directories and root files.
to_copy = %w(app config db public script CONTRIBUTORS LICENSE Rakefile README).map do |dir|
File.join REFINERY_ROOT, dir
end
FileUtils::cp_r to_copy, RAILS_ROOT, :verbose => false
# add in the database config file.
FileUtils::move File.join(RAILS_ROOT, %w(config database.yml.example)), File.join(RAILS_ROOT, %w(config database.yml))
# figure out the database name from the install path and swap out your_local_database with this name.
unless RAILS_ROOT == "/" or RUBY_PLATFORM =~ /mswin/
database_name = RAILS_ROOT.split(File::SEPARATOR).last
# read in the file and split up the lines
lines = File.open(File.join(RAILS_ROOT, %w(config database.yml)), "r").read.split("\n")
lines.each do |line|
line.gsub!("your_local_database", database_name)
line.gsub!("your_test_database", "#{database_name}_test")
line.gsub!("your_production_database", "#{database_name}_production")
end
# write the new content into the file.
File.open(File.join(RAILS_ROOT, %w(config database.yml)), "w").puts(lines.join("\n"))
else
database_name = "your_local_database"
end
# update the environment file with a new secret key.
require 'digest/sha1'
new_digest = ""
3.times { new_digest << Digest::SHA1.hexdigest("--refinery--#{Time.now.to_s}--#{rand(10000000)}--") }
# read in the file and split up the lines
lines = File.open(File.join(RAILS_ROOT, %w(config environment.rb)), "r").read.split("\n")
lines.each do |line|
match = line.scan(/(:secret)([^']*)([\'])([^\']*)/).flatten.last
line.gsub!(match, new_digest) unless match.nil?
end
# write the new content into the file.
File.open(File.join(RAILS_ROOT, %w(config environment.rb)), "w").puts(lines.join("\n"))
puts "\n---------"
puts "Refinery successfully installed in '#{RAILS_ROOT}'!\n\n"
# update core script files with symlinks.
system "refinery-update-core #{RAILS_ROOT} --from-refinery-installer"
puts "=== ACTION REQUIRED ==="
puts "\nNow run these commands:"
puts "\ncd #{RAILS_ROOT}"
puts "rake gems:install"
puts "rake db:setup"
puts "\nruby script/server"
puts "\nThis will install all the required gems, set up your database (named '#{database_name}') and launches the built-in webserver."
puts "You can now see your site running in your browser at http://localhost:3000"
puts "\nThanks for installing Refinery, enjoy creating your new application!"
puts "---------\n\n"
end
else
puts "Please specify the path where you want to install Refinery. i.e. refinery /path/to/project"
end