matthewgarysmith-ubuntu-machine 0.3.1.2 → 0.3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,41 +3,56 @@ namespace :machine do
|
|
3
3
|
desc "Change the root password, create a new user and allow him to sudo and to SSH"
|
4
4
|
task :initial_setup do
|
5
5
|
set :user_to_create , user
|
6
|
-
set :user,
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
set :user, username = Capistrano::CLI.ui.ask("Login as? (#{root_user}) : ")
|
7
|
+
sure = Capistrano::CLI.ui.ask("Change the password for #{user}? (y/N) : ")
|
8
|
+
if sure.to_s.strip.downcase == 'y'
|
9
|
+
run "passwd", :pty => true do |ch, stream, data|
|
10
|
+
if data =~ /UNIX password/
|
11
|
+
# prompt, and then send the response to the remote process
|
12
|
+
ch.send_data(Capistrano::CLI.password_prompt(data) + "\n")
|
13
|
+
else
|
14
|
+
# use the default handler for all other text
|
15
|
+
Capistrano::Configuration.default_io_proc.call(ch, stream, data)
|
16
|
+
end
|
16
17
|
end
|
17
18
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
|
20
|
+
users = capture('cat /etc/passwd | cut -d":" -f1').split(/\s+/)
|
21
|
+
if users.include?(user_to_create)
|
22
|
+
puts "-- user: #{user_to_create.inspect} already exists."
|
23
|
+
else
|
24
|
+
sudo "adduser #{user_to_create}", :pty => true do |ch, stream, data|
|
25
|
+
if data =~ /UNIX password/ || data=~/\[\]\:/ || data=~/\[y\/N\]/i
|
26
|
+
# prompt, and then send the response to the remote process
|
27
|
+
ch.send_data(Capistrano::CLI.password_prompt(data) + "\n")
|
28
|
+
else
|
29
|
+
# use the default handler for all other text
|
30
|
+
Capistrano::Configuration.default_io_proc.call(ch, stream, data)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
sudoers_file = capture("cat /etc/sudoers", :via => :sudo)
|
36
|
+
if sudoers_file.include? "#{user_to_create} ALL=(ALL)ALL"
|
37
|
+
puts "-- #{user_to_create} is already a sudoer"
|
38
|
+
else
|
39
|
+
sudo" bash -c \"echo '#{user_to_create} ALL=(ALL)ALL' >> /etc/sudoers\""
|
40
|
+
if setup_ssh
|
41
|
+
#this next line effectively prevents the root user from ssh access by only allowing the new user
|
42
|
+
sudo" bash -c \"echo 'AllowUsers #{user_to_create}' >> /etc/ssh/sshd_config\""
|
43
|
+
sudo "/etc/init.d/ssh reload"
|
26
44
|
end
|
27
45
|
end
|
28
|
-
|
29
|
-
run "echo '#{user_to_create} ALL=(ALL)ALL' >> /etc/sudoers"
|
30
|
-
run "echo 'AllowUsers #{user_to_create}' >> /etc/ssh/sshd_config"
|
31
|
-
run "/etc/init.d/ssh reload"
|
32
46
|
end
|
33
|
-
|
47
|
+
|
34
48
|
task :configure do
|
35
49
|
ssh.setup
|
36
50
|
iptables.configure
|
37
51
|
aptitude.setup
|
38
52
|
end
|
39
|
-
|
53
|
+
|
40
54
|
task :install_dev_tools do
|
55
|
+
curl.install
|
41
56
|
mysql.install
|
42
57
|
apache.install
|
43
58
|
ruby.install
|
@@ -47,11 +62,11 @@ namespace :machine do
|
|
47
62
|
git.install
|
48
63
|
php.install
|
49
64
|
end
|
50
|
-
|
65
|
+
|
51
66
|
desc = "Ask for a user and change his password"
|
52
67
|
task :change_password do
|
53
68
|
user_to_update = Capistrano::CLI.ui.ask("Name of the user whose you want to update the password : ")
|
54
|
-
|
69
|
+
|
55
70
|
sudo "passwd #{user_to_update}", :pty => true do |ch, stream, data|
|
56
71
|
if data =~ /Enter new UNIX password/ || data=~ /Retype new UNIX password:/
|
57
72
|
# prompt, and then send the response to the remote process
|
@@ -45,7 +45,7 @@ namespace :mysql do
|
|
45
45
|
create_db_tmp_file = "create_#{db_name}.sql"
|
46
46
|
put render("new_db", binding), create_db_tmp_file
|
47
47
|
run "mysql -u root -p#{db_root_password} < #{create_db_tmp_file}"
|
48
|
-
|
48
|
+
|
49
49
|
run "mysql -u root -p#{db_root_password} #{db_name} < #{file}"
|
50
50
|
run "rm #{file} #{create_db_tmp_file}"
|
51
51
|
end
|
@@ -55,15 +55,16 @@ namespace :mysql do
|
|
55
55
|
db_root_password = Capistrano::CLI.ui.ask("Choose a MySQL root password : ")
|
56
56
|
sudo "aptitude install -y mysql-server mysql-client libmysqlclient15-dev"
|
57
57
|
sudo "aptitude install -y libmysql-ruby1.8"
|
58
|
+
restart
|
58
59
|
run "mysqladmin -u root password #{db_root_password}"
|
59
60
|
end
|
60
|
-
|
61
|
+
|
61
62
|
desc "Ask for a MySQL user and change his password"
|
62
63
|
task :change_password, :roles => :db do
|
63
64
|
user_to_update = Capistrano::CLI.ui.ask("Name of the MySQL user whose you want to update the password : ")
|
64
65
|
old_password = Capistrano::CLI.ui.ask("Old password for #{user_to_update} : ")
|
65
66
|
new_password = Capistrano::CLI.ui.ask("New password for #{user_to_update} : ")
|
66
|
-
|
67
|
+
|
67
68
|
run "mysqladmin -u #{user_to_update} -p#{old_password} password \"#{new_password}\""
|
68
69
|
end
|
69
70
|
end
|
@@ -1,17 +1,19 @@
|
|
1
1
|
namespace :ssh do
|
2
|
-
|
2
|
+
|
3
3
|
desc <<-DESC
|
4
4
|
Setup SSH on the gateway host. Runs `upload_keys`, `install_ovh_ssh_key` AND \
|
5
5
|
`configure_sshd` then reloads the SSH service to finalize the changes.
|
6
6
|
DESC
|
7
7
|
task :setup, :roles => :gateway do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
if setup_ssh
|
9
|
+
upload_keys
|
10
|
+
configure_sshd
|
11
|
+
install_ovh_ssh_key if ["ovh-rps", "ovh-dedie"].include?(hosting_provider)
|
12
|
+
reload
|
13
|
+
end
|
12
14
|
end
|
13
|
-
|
14
|
-
|
15
|
+
|
16
|
+
|
15
17
|
desc <<-DESC
|
16
18
|
Uploads your local public SSH keys to the server. A .ssh folder is created if \
|
17
19
|
one does not already exist. The SSH keys default to the ones set in \
|
@@ -26,10 +28,11 @@ namespace :ssh do
|
|
26
28
|
run "chown -R #{user}:#{user} ~/.ssh"
|
27
29
|
run "chmod 700 ~/.ssh"
|
28
30
|
|
29
|
-
|
31
|
+
key_path = File.expand_path(ssh_options[:keys])
|
32
|
+
authorized_keys = key_path.collect { |key| File.read("#{key}.pub") }.join("\n")
|
30
33
|
put authorized_keys, "./.ssh/authorized_keys2", :mode => 0600
|
31
34
|
end
|
32
|
-
|
35
|
+
|
33
36
|
desc <<-DESC
|
34
37
|
Configure SSH daemon with more secure settings recommended by Slicehost. The \
|
35
38
|
will be configured to run on the port configured in Capistrano's "ssh_options". \
|
@@ -44,7 +47,7 @@ namespace :ssh do
|
|
44
47
|
put render("sshd_config", binding), "sshd_config"
|
45
48
|
sudo "mv sshd_config /etc/ssh/sshd_config"
|
46
49
|
end
|
47
|
-
|
50
|
+
|
48
51
|
desc <<-DESC
|
49
52
|
Install OVH SSH Keys
|
50
53
|
DESC
|
@@ -52,13 +55,13 @@ namespace :ssh do
|
|
52
55
|
sudo "wget ftp://ftp.ovh.net/made-in-ovh/cle-ssh-public/installer_la_cle.sh -O installer_la_cle.sh"
|
53
56
|
sudo "sh installer_la_cle.sh"
|
54
57
|
end
|
55
|
-
|
58
|
+
|
56
59
|
desc <<-DESC
|
57
60
|
Reload SSH service.
|
58
61
|
DESC
|
59
62
|
task :reload, :roles => :gateway do
|
60
63
|
sudo "/etc/init.d/ssh reload"
|
61
64
|
end
|
62
|
-
|
63
|
-
|
65
|
+
|
66
|
+
|
64
67
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matthewgarysmith-ubuntu-machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.1.
|
4
|
+
version: 0.3.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Balthazar
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-02-09 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- MIT-LICENSE
|
35
35
|
- lib/capistrano/ext/ubuntu-machine.rb
|
36
36
|
- lib/capistrano/ext/ubuntu-machine
|
37
|
+
- lib/capistrano/ext/ubuntu-machine/curl.rb
|
37
38
|
- lib/capistrano/ext/ubuntu-machine/ruby.rb
|
38
39
|
- lib/capistrano/ext/ubuntu-machine/gems.rb
|
39
40
|
- lib/capistrano/ext/ubuntu-machine/git.rb
|