sprout 0.7.162 → 0.7.163
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sprout might be problematic. Click here for more details.
- data/lib/sprout/general_tasks.rb +1 -0
- data/lib/sprout/tasks/sftp_task.rb +7 -7
- data/lib/sprout/tasks/ssh_task.rb +150 -0
- data/lib/sprout/version.rb +1 -1
- metadata +3 -2
data/lib/sprout/general_tasks.rb
CHANGED
@@ -74,14 +74,13 @@ module Sprout
|
|
74
74
|
# provided here as a convenience for getting set up.
|
75
75
|
attr_accessor :password
|
76
76
|
|
77
|
-
# TODO: Get this to automatically download and install requisite gems
|
78
77
|
def initialize(task_name, app)
|
79
78
|
super(task_name, app)
|
80
79
|
@name = name
|
81
80
|
@files = []
|
82
|
-
@host = ''
|
83
81
|
@dir_mode = 0755
|
84
82
|
@file_mode = 0644
|
83
|
+
@host = nil
|
85
84
|
end
|
86
85
|
|
87
86
|
def self.define_task(args, &block) # :nodoc:
|
@@ -95,7 +94,7 @@ module Sprout
|
|
95
94
|
expr = @local_path + '/**/**/*'
|
96
95
|
@files = FileList[expr]
|
97
96
|
else
|
98
|
-
|
97
|
+
raise SFTPError.new('SFTP requires either a local_path or files to be transmitted')
|
99
98
|
end
|
100
99
|
else
|
101
100
|
if(!@local_path)
|
@@ -103,20 +102,21 @@ module Sprout
|
|
103
102
|
end
|
104
103
|
end
|
105
104
|
|
106
|
-
if(@host
|
107
|
-
|
105
|
+
if(@host.nil?)
|
106
|
+
raise SFTPError.new('SFTP requires non-nil host parameter')
|
108
107
|
end
|
109
108
|
|
110
109
|
if(@username.nil?)
|
111
110
|
print "Username: "
|
112
111
|
@username = $stdin.gets.chomp!
|
113
|
-
|
112
|
+
raise SFTPError.new('SFTP requires username parameter') unless @username
|
114
113
|
end
|
115
114
|
|
116
115
|
if(@password.nil?)
|
116
|
+
print "Password: "
|
117
117
|
@password = $stdin.gets.chomp!
|
118
118
|
# @password = Password.get
|
119
|
-
|
119
|
+
raise SFTPError.new('SFTP requires password parameter') unless @password
|
120
120
|
end
|
121
121
|
|
122
122
|
if(get_confirmation)
|
@@ -0,0 +1,150 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2007 Pattern Park
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
This class has been commented out because the termios feature
|
24
|
+
that allows users to more securely enter passwords does not
|
25
|
+
work in a DOS shell.
|
26
|
+
|
27
|
+
It would be greatly appreciate if someone refactored this to either:
|
28
|
+
a) Get the same functionality in a cross-platform manner
|
29
|
+
b) Only require and use termios on systems that allow it
|
30
|
+
=end
|
31
|
+
|
32
|
+
|
33
|
+
require 'net/ssh'
|
34
|
+
require 'net/sftp'
|
35
|
+
#require 'termios'
|
36
|
+
|
37
|
+
module Sprout
|
38
|
+
class SSHError < StandardError #:nodoc:
|
39
|
+
end
|
40
|
+
|
41
|
+
# The SSHTask allows you to execute arbitrary commands on a remote host.
|
42
|
+
#
|
43
|
+
# ssh :update_gem_index do |t|
|
44
|
+
# t.host = 'dev.projectsprouts.com'
|
45
|
+
# t.username = 'someUser'
|
46
|
+
# t.commands << 'cd /var/www/projectsprouts/current/gems'
|
47
|
+
# t.commands << 'gem generate_index -d .'
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
class SSHTask < Rake::Task
|
51
|
+
|
52
|
+
# Host name of the server to connect to with no protocol prefix, like: sub.yourhost.com
|
53
|
+
attr_accessor :host
|
54
|
+
# Array of commands that will be executed on the remote machine
|
55
|
+
attr_accessor :commands
|
56
|
+
# Username to send to the remote host. You will be prompted for this value if it is left null.
|
57
|
+
attr_accessor :username
|
58
|
+
# Password to send to the remote host. You will be prompted for this value if it is left null.
|
59
|
+
#
|
60
|
+
# NOTE: You should never check a file into version control with this field filled in, it is
|
61
|
+
# provided here as a convenience for getting set up.
|
62
|
+
attr_accessor :password
|
63
|
+
|
64
|
+
def initialize(task_name, app)
|
65
|
+
super(task_name, app)
|
66
|
+
@name = name
|
67
|
+
@host = nil
|
68
|
+
@commands = []
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.define_task(args, &block) # :nodoc:
|
72
|
+
t = super
|
73
|
+
yield t if block_given?
|
74
|
+
end
|
75
|
+
|
76
|
+
def execute(*args) # :nodoc:
|
77
|
+
if(@host.nil?)
|
78
|
+
throw SSHError.new('SSH requires a valid host parameter')
|
79
|
+
end
|
80
|
+
|
81
|
+
if(@username.nil?)
|
82
|
+
print "Username: "
|
83
|
+
@username = $stdin.gets.chomp!
|
84
|
+
raise SFTPError.new('SFTP requires username parameter') unless @username
|
85
|
+
end
|
86
|
+
|
87
|
+
if(@password.nil?)
|
88
|
+
print "Password: "
|
89
|
+
@password = $stdin.gets.chomp!
|
90
|
+
# @password = Password.get
|
91
|
+
raise SFTPError.new('SFTP requires password parameter') unless @password
|
92
|
+
end
|
93
|
+
|
94
|
+
puts ">> Connecting to Remote Server: #{@username}@#{@host}:#{@remote_path}"
|
95
|
+
Net::SSH.start(@host, @username, @password) do |session|
|
96
|
+
session.open_channel do |channel|
|
97
|
+
commands.each do |command|
|
98
|
+
puts ">> #{command}"
|
99
|
+
channel.exec command
|
100
|
+
end
|
101
|
+
channel.close
|
102
|
+
end
|
103
|
+
session.loop
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
=begin
|
110
|
+
# The following implementation does not work at all on DOS machines,
|
111
|
+
# is there a cross-platform way to solve the secure password prompt problem?
|
112
|
+
# Password handling snippet found at: http://www.caliban.org/ruby/ruby-password.shtml
|
113
|
+
class Password
|
114
|
+
|
115
|
+
def Password.get(message="Password: ")
|
116
|
+
begin
|
117
|
+
if $stdin.tty?
|
118
|
+
Password.echo false
|
119
|
+
print message if message
|
120
|
+
end
|
121
|
+
|
122
|
+
return $stdin.gets.chomp
|
123
|
+
ensure
|
124
|
+
if $stdin.tty?
|
125
|
+
Password.echo true
|
126
|
+
print "\n"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def Password.echo(on=true, masked=false)
|
132
|
+
term = Termios::getattr( $stdin )
|
133
|
+
|
134
|
+
if on
|
135
|
+
term.c_lflag |= ( Termios::ECHO | Termios::ICANON )
|
136
|
+
else # off
|
137
|
+
term.c_lflag &= ~Termios::ECHO
|
138
|
+
term.c_lflag &= ~Termios::ICANON if masked
|
139
|
+
end
|
140
|
+
|
141
|
+
Termios::setattr( $stdin, Termios::TCSANOW, term )
|
142
|
+
end
|
143
|
+
end
|
144
|
+
=end
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
def ssh(args, &block)
|
149
|
+
Sprout::SSHTask.define_task(args, &block)
|
150
|
+
end
|
data/lib/sprout/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.163
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Bayes
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-02-
|
12
|
+
date: 2008-02-20 00:00:00 -08:00
|
13
13
|
default_executable: sprout
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- lib/sprout/tasks/gem_wrap_task.rb
|
92
92
|
- lib/sprout/tasks/library_task.rb
|
93
93
|
- lib/sprout/tasks/sftp_task.rb
|
94
|
+
- lib/sprout/tasks/ssh_task.rb
|
94
95
|
- lib/sprout/tasks/tool_task.rb
|
95
96
|
- lib/sprout/tasks/zip_task.rb
|
96
97
|
- lib/sprout/template_resolver.rb
|