forked from benhoskings/babushka-deps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.rb
39 lines (34 loc) · 1.26 KB
/
mysql.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
dep 'mysql.gem' do
requires 'mysql.managed'
provides []
end
dep 'mysql access' do
requires 'existing mysql db'
define_var :db_user, :default => :username
define_var :db_host, :default => 'localhost'
met? { mysql "use #{var(:db_name)}", var(:db_user) }
meet { mysql %Q{GRANT ALL PRIVILEGES ON #{var :db_name}.* TO '#{var :db_user}'@'#{var :db_host}' IDENTIFIED BY '#{var :db_password}'} }
end
dep 'existing mysql db' do
requires 'mysql configured'
met? { mysql("SHOW DATABASES").split("\n")[1..-1].any? {|l| /\b#{var :db_name}\b/ =~ l } }
meet { mysql "CREATE DATABASE #{var :db_name}" }
end
dep 'mysql configured' do
requires 'mysql root password'
end
dep 'mysql root password' do
requires 'mysql.managed'
met? { raw_shell("echo '\q' | mysql -u root").stderr["Access denied for user 'root'@'localhost' (using password: NO)"] }
meet { mysql(%Q{GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '#{var :db_admin_password}'}, 'root', false) }
end
dep 'mysql.managed' do
installs {
via :apt, %w[mysql-server libmysqlclient16-dev]
via :macports, 'mysql5-server'
}
provides 'mysql'
after :on => :osx do
sudo "ln -s #{Babushka::MacportsHelper.prefix / 'lib/mysql5/bin/mysql*'} #{Babushka::MacportsHelper.prefix / 'bin/'}"
end
end