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
|
# File 'lib/pointer/postgres.rb', line 3
def install_postgres
unless @ssh.exec! 'which psql'
puts @ssh.exec! 'sudo apt-get install -y libpq-dev'
puts @ssh.exec! 'sudo apt-get install -y software-properties-common'
puts @ssh.exec! 'sudo add-apt-repository ppa:pitti/postgresql'
puts @ssh.exec! 'sudo apt-get update'
puts @ssh.exec! 'sudo apt-get install -y postgresql-9.2'
end
if file_absent("#{@options[:site_dir]}/shared/config/database.yml")
o = [('a'..'z'), ('A'..'Z'), ('0'..'9')].map { |i| i.to_a }.flatten
password = (0...16).map { o[rand(o.length)] }.join
username = 'user_' + host.gsub(/[^a-z0-9]/, '_')
database = 'db_' + host.gsub(/[^a-z0-9]/, '_')
puts @ssh.exec!("sudo sudo -u postgres psql -c \"CREATE ROLE #{username} WITH CREATEDB LOGIN PASSWORD '#{password}'\"")
puts @ssh.exec!("sudo sudo -u postgres psql -c \"CREATE DATABASE #{database} OWNER #{username}\"");
"production:\n" +
" adapter: postgresql\n" +
" host: 127.0.0.1\n" +
" encoding: utf8\n" +
" database: #{database}\n" +
" username: #{username}\n" +
" password: #{password}\n" +
''
else
nil
end
end
|