|
1 | 1 | # coding: utf-8 |
2 | | -define :magento_database do |
| 2 | + |
| 3 | +installed_file = '/root/.magento.db.installed' |
| 4 | + |
| 5 | +unless File.exist?(installed_file) |
3 | 6 |
|
4 | 7 | include_recipe 'mysql::server' |
5 | 8 | include_recipe 'mysql::client' |
6 | 9 | include_recipe 'mysql-chef_gem' |
7 | 10 |
|
| 11 | + root_password = node[:mysql][:server_root_password] |
| 12 | + db_config = node[:magento][:db] |
| 13 | + |
8 | 14 | execute 'mysql-install-mage-privileges' do |
9 | 15 | command <<-EOH |
10 | | - /usr/bin/mysql -u root -p#{node[:mysql][:server_root_password]} < \ |
| 16 | + /usr/bin/mysql -u root -p#{root_password} < \ |
11 | 17 | /etc/mysql/mage-grants.sql |
12 | 18 | EOH |
13 | 19 | action :nothing |
|
26 | 32 |
|
27 | 33 | execute "create #{node[:magento][:db][:database]} database" do |
28 | 34 | command <<-EOH |
29 | | - /usr/bin/mysqladmin -u root -p#{node[:mysql][:server_root_password]} \ |
| 35 | + /usr/bin/mysqladmin -u root -p#{root_password} \ |
30 | 36 | create #{node[:magento][:db][:database]} |
31 | 37 | EOH |
32 | 38 | not_if do |
33 | 39 | require 'rubygems' |
34 | 40 | Gem.clear_paths |
35 | 41 | require 'mysql' |
36 | | - m = Mysql.new('localhost', 'root', node[:mysql][:server_root_password]) |
| 42 | + m = Mysql.new('localhost', 'root', root_password) |
37 | 43 | m.list_dbs.include?(node[:magento][:db][:database]) |
38 | 44 | end |
39 | 45 | end |
|
50 | 56 | end |
51 | 57 | end |
52 | 58 |
|
| 59 | + # Import Sample Data |
| 60 | + unless node[:magento][:sample_data_url].empty? |
| 61 | + include_recipe 'mysql::client' |
| 62 | + |
| 63 | + remote_file File.join(Chef::Config[:file_cache_path], |
| 64 | + 'magento-sample-data.tar.gz') do |
| 65 | + source node[:magento][:sample_data_url] |
| 66 | + mode 0644 |
| 67 | + end |
| 68 | + |
| 69 | + bash 'magento-sample-data' do |
| 70 | + cwd "#{Chef::Config[:file_cache_path]}" |
| 71 | + code <<-EOH |
| 72 | + mkdir #{name} |
| 73 | + cd #{name} |
| 74 | + tar --strip-components 1 -xzf \ |
| 75 | + #{Chef::Config[:file_cache_path]}/magento-sample-data.tar.gz |
| 76 | + mv media/* #{node[:magento][:dir]}/media/ |
| 77 | +
|
| 78 | + mv magento_sample_data*.sql data.sql 2>/dev/null |
| 79 | + /usr/bin/mysql -h #{db_config[:host]} -u #{db_config[:username]} \ |
| 80 | + -p#{db_config[:password]} #{db_config[:database]} < data.sql |
| 81 | + cd .. |
| 82 | + rm -rf #{name} |
| 83 | + EOH |
| 84 | + end |
| 85 | + end |
53 | 86 | end |
0 commit comments