-
Notifications
You must be signed in to change notification settings - Fork 16
/
setup.rb
executable file
·124 lines (108 loc) · 3.35 KB
/
setup.rb
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/ruby
require 'etc'
require 'fileutils'
prereqs = {
apachectl: 'apache2',
curl: 'curl',
git: 'git',
mysql: 'libmysqlclient-dev mysql-server',
nodejs: 'nodejs',
chromedriver: 'chromium-chromedriver',
bison: 'bison libffi-dev libgdbm-dev libyaml-dev pkg-config libreadline-dev libssl-dev'
}
prereqs[:mysql].sub! '-server', '-client' if File.exist? '/.dockerenv'
# accept node as an alias for nodejs; not absolutely required on Mac OS/X
prereqs.delete :nodejs unless `which node`.empty?
prereqs.delete :nodejs if RUBY_PLATFORM.include? 'darwin'
# check prereqs
prereqs.keys.each do |cmd|
next unless `which #{cmd}`.empty?
if Process.uid == 0
system "apt-get install -y #{prereqs[cmd]}"
elsif %(awdwr vagrant ubuntu).include? Etc.getlogin
system "sudo apt-get install -y #{prereqs[cmd]}"
else
STDERR.puts "Unable to find #{cmd}"
exit -1
end
end
unless RUBY_PLATFORM.include? 'darwin'
unless %w(nodejs node).any? {|cmd| not `which #{cmd}`.empty?}
STDERR.puts "Unable to find nodejs"
exit -1
end
end
# set up mysql
mysql_root = (File.exist?('/.dockerenv') ? '' : '-u root')
if ENV['MYSQL_ROOT_PASSWD']
mysql_root += " -p#{ENV['MYSQL_ROOT_PASSWD']}"
elsif system("mysql -u root -proot < /dev/null 2>&0")
mysql_root += ' -proot'
end
open("|mysql #{mysql_root}",'w') do |file|
file.write <<-EOF
CREATE USER IF NOT EXISTS 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON depot_production.* TO 'username'@'localhost';
EOF
end
# set up postgres
unless `which psql`.empty?
open('|psql postgres','w') do |file|
file.write <<-EOF
DROP ROLE IF EXISTS username;
CREATE ROLE username LOGIN PASSWORD 'password';
EOF
end
end
# fetch code
repositories = %w(
[email protected]:rubys/awdwr.git
[email protected]:rubys/gorp.git
git://github.com/rails/rails.git
)
require 'fileutils'
git_path = File.expand_path('~/git')
FileUtils.mkdir_p git_path
Dir.chdir git_path do
repositories.each do |repository|
next if File.exist? File.basename(repository, '.git')
repository.sub! '@github.com:', '://github.com/' unless ENV['USER']=='rubys'
system "git clone #{repository}"
end
end
if `which rbenv`.empty?
unless `gpg -k`.include? 'mpapis'
system 'command curl -sSL https://rvm.io/mpapis.asc | gpg --import -'
end
unless `gpg -k`.include? 'Piotr'
system 'command curl -sSL https://rvm.io/pkuczynski.asc | gpg --import -'
end
rvm_path = File.expand_path(ENV['rvm_path'] || '~/.rvm')
if not File.exist? rvm_path
# download key
unless `gpg --list-keys`.include? 'D39DC0E3'
system 'gpg --keyserver hkp://keys.gnupg.net --recv-keys ' +
'409B6B1796C275462A1703113804BB82D39DC0E3'
end
# install rvm
system 'bash -c "curl -L https://get.rvm.io | bash -s stable"'
exit -1 unless File.exist? rvm_path
cmd = "source #{rvm_path}/scripts/rvm; rvm default system; " +
"rvm --autolibs=enable requirements ruby-2.6.1"
system 'bash -c ' + cmd.inspect
end
end
if `which bundler`.empty?
if ENV['rvm_version']
system 'gem install bundler'
else
system 'sudo gem install bundler'
end
end
if `git config --get user.email`.empty?
system 'git config --global user.email "[email protected]"'
end
if `git config --get user.name`.empty?
system 'git config --global user.name "Sam Ruby"'
end
FileUtils.mkdir_p File.expand_path('~/logs')