exec_remote 0.0.1
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.
- data/CHANGELOG.rdoc +3 -0
- data/Manifest +11 -0
- data/README.rdoc +8 -0
- data/Rakefile +28 -0
- data/bin/exec_remote +4 -0
- data/exec_remote.gemspec +35 -0
- data/lib/exec_remote/cli.rb +53 -0
- data/lib/exec_remote/configuration.rb +69 -0
- data/lib/exec_remote/remote_executor.rb +42 -0
- data/lib/exec_remote/shell.rb +39 -0
- data/lib/exec_remote.rb +3 -0
- data/spec/functional/basic_spec.rb +2 -0
- metadata +86 -0
data/CHANGELOG.rdoc
ADDED
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
Exec Remote is a simple utility to run tests/build against your development code in a remote machine
|
2
|
+
without checking in to a repository.
|
3
|
+
|
4
|
+
It sync ups your code in local and remote machine with rsync and
|
5
|
+
the commands are executed in remote machine via SSH
|
6
|
+
|
7
|
+
|
8
|
+
More coming soon.
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
begin
|
2
|
+
require 'echoe'
|
3
|
+
rescue LoadError
|
4
|
+
abort "gem 'echoe' is required"
|
5
|
+
end
|
6
|
+
|
7
|
+
version = "0.0.1"
|
8
|
+
|
9
|
+
Echoe.new('exec_remote', version) do |p|
|
10
|
+
p.include_gemspec = true
|
11
|
+
p.changelog = "CHANGELOG.rdoc"
|
12
|
+
|
13
|
+
p.author = "Selvakumar Natesan"
|
14
|
+
p.email = "k.n.selvakumar@gmail.com"
|
15
|
+
|
16
|
+
p.summary = <<-DESC.strip.gsub(/\n\s+/, " ")
|
17
|
+
Exec Remote is a simple utility to run tests/build against your development code in a remote machine
|
18
|
+
without checking in to a repository.
|
19
|
+
|
20
|
+
It sync ups your code in local and remote machine with rsync and
|
21
|
+
the commands are executed in remote machine via SSH
|
22
|
+
DESC
|
23
|
+
|
24
|
+
p.url = "https://github.com/selvakn/exec_remote"
|
25
|
+
p.rdoc_pattern = /^(lib|README.rdoc|CHANGELOG.rdoc)/
|
26
|
+
|
27
|
+
p.dependencies = ["net-ssh"]
|
28
|
+
end
|
data/bin/exec_remote
ADDED
data/exec_remote.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{exec_remote}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Selvakumar Natesan"]
|
9
|
+
s.date = %q{2009-10-03}
|
10
|
+
s.default_executable = %q{exec_remote}
|
11
|
+
s.description = %q{Exec Remote is a simple utility to run tests/build against your development code in a remote machine without checking in to a repository. It sync ups your code in local and remote machine with rsync and the commands are executed in remote machine via SSH}
|
12
|
+
s.email = %q{k.n.selvakumar@gmail.com}
|
13
|
+
s.executables = ["exec_remote"]
|
14
|
+
s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.rdoc", "lib/exec_remote.rb", "lib/exec_remote/cli.rb", "lib/exec_remote/configuration.rb", "lib/exec_remote/remote_executor.rb", "lib/exec_remote/shell.rb"]
|
15
|
+
s.files = ["CHANGELOG.rdoc", "Manifest", "README.rdoc", "Rakefile", "bin/exec_remote", "lib/exec_remote.rb", "lib/exec_remote/cli.rb", "lib/exec_remote/configuration.rb", "lib/exec_remote/remote_executor.rb", "lib/exec_remote/shell.rb", "spec/functional/basic_spec.rb", "exec_remote.gemspec"]
|
16
|
+
s.homepage = %q{https://github.com/selvakn/exec_remote}
|
17
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Exec_remote", "--main", "README.rdoc"]
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.rubyforge_project = %q{exec_remote}
|
20
|
+
s.rubygems_version = %q{1.3.4}
|
21
|
+
s.summary = %q{Exec Remote is a simple utility to run tests/build against your development code in a remote machine without checking in to a repository. It sync ups your code in local and remote machine with rsync and the commands are executed in remote machine via SSH}
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 3
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
s.add_runtime_dependency(%q<net-ssh>, [">= 0"])
|
29
|
+
else
|
30
|
+
s.add_dependency(%q<net-ssh>, [">= 0"])
|
31
|
+
end
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<net-ssh>, [">= 0"])
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'exec_remote'
|
2
|
+
|
3
|
+
module ExecRemote
|
4
|
+
class CLI
|
5
|
+
|
6
|
+
def self.config
|
7
|
+
@@config ||= Configuration.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.execute
|
11
|
+
begin
|
12
|
+
puts "Exec Remote Shell"
|
13
|
+
puts "================="
|
14
|
+
|
15
|
+
rsync
|
16
|
+
|
17
|
+
puts "Enter your commands now"
|
18
|
+
shell = Shell.new
|
19
|
+
while(true)
|
20
|
+
process_command shell.read_line
|
21
|
+
end
|
22
|
+
rescue StandardError => e
|
23
|
+
puts "Exiting because of error: #{e}"
|
24
|
+
raise e
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.process_command(command)
|
29
|
+
if command[0,1] == "!"
|
30
|
+
command = command[1..-1]
|
31
|
+
print "again? "
|
32
|
+
rsync
|
33
|
+
end
|
34
|
+
|
35
|
+
exit if command == "exit"
|
36
|
+
exec_remote command
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.exec_remote(command)
|
40
|
+
command = command.to_s.strip
|
41
|
+
command_to_exec = "cd #{config.my_current_project_dir_on_remote} && #{command}"
|
42
|
+
RemoteExecutor.connect_and_execute(command_to_exec, config.remote_host, config.remote_user) unless command.empty?
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.rsync
|
46
|
+
rsync_command = <<EOS
|
47
|
+
rsync -r --exclude=.git #{config.current_dir} #{config.remote_user}@#{config.remote_host}:#{config.my_dir_on_remote}
|
48
|
+
EOS
|
49
|
+
puts "rsyncing.."; `#{rsync_command}`
|
50
|
+
puts "Done"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module ExecRemote
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
def exec_config
|
5
|
+
config = config_from_file
|
6
|
+
updated_config = update_config_from_user(config.dup)
|
7
|
+
|
8
|
+
return config if config == updated_config
|
9
|
+
File.open(config_file, "w") {|f| f.puts updated_config.to_yaml}
|
10
|
+
exec_config
|
11
|
+
end
|
12
|
+
|
13
|
+
def current_dir
|
14
|
+
Dir.pwd
|
15
|
+
end
|
16
|
+
|
17
|
+
def current_project
|
18
|
+
File.basename(current_dir)
|
19
|
+
end
|
20
|
+
|
21
|
+
def remote_host
|
22
|
+
exec_config["host"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def remote_user
|
26
|
+
exec_config["user"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def my_dir_on_remote
|
30
|
+
File.join(exec_config["base_location"], exec_config["location"])
|
31
|
+
end
|
32
|
+
|
33
|
+
def my_current_project_dir_on_remote
|
34
|
+
File.join(my_dir_on_remote, current_project)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def config_from_file
|
39
|
+
return {} unless File.exists?(config_file)
|
40
|
+
YAML.load_file config_file
|
41
|
+
end
|
42
|
+
|
43
|
+
def update_config_from_user(config = {})
|
44
|
+
config = check_and_update_config(config, "host", "the remote hostname/ip")
|
45
|
+
config = check_and_update_config(config, "user", "the remote host username")
|
46
|
+
config = check_and_update_config(config, "location", "your location on remote host", current_project)
|
47
|
+
config["base_location"] ||= "data"
|
48
|
+
config
|
49
|
+
end
|
50
|
+
|
51
|
+
def check_and_update_config(config, config_name, description = config_name, default_value = nil)
|
52
|
+
return config if config[config_name]
|
53
|
+
print "Enter #{description}: "
|
54
|
+
print "[#{default_value}] " if default_value
|
55
|
+
|
56
|
+
config[config_name] = strip_string(gets) || default_value
|
57
|
+
config
|
58
|
+
end
|
59
|
+
|
60
|
+
def config_file
|
61
|
+
File.join(current_dir, ".exec_remote.yml")
|
62
|
+
end
|
63
|
+
|
64
|
+
def strip_string(string)
|
65
|
+
str = string.strip
|
66
|
+
str.empty? ? nil : str
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'net-ssh'
|
3
|
+
require 'net/ssh'
|
4
|
+
|
5
|
+
module ExecRemote
|
6
|
+
class RemoteExecutor
|
7
|
+
def self.connect_and_execute(command, host, user, pass = nil)
|
8
|
+
ssh_connect(host, user, pass) do |ssh|
|
9
|
+
execute(ssh, command)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.ssh_connect(host, user, password, &block)
|
14
|
+
puts "Connecting.."
|
15
|
+
::Net::SSH.start(host, user, :password => password, :config=>false, :paranoid=>false) do |ssh|
|
16
|
+
yield(ssh)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.execute(ssh_connection, command)
|
21
|
+
ssh_connection.open_channel do |channel|
|
22
|
+
channel.request_pty do |ch, success|
|
23
|
+
if success
|
24
|
+
ch.exec "sh -c '#{command}'"
|
25
|
+
else
|
26
|
+
ch.close
|
27
|
+
end
|
28
|
+
|
29
|
+
ch.on_data do |c, data|
|
30
|
+
print data
|
31
|
+
end
|
32
|
+
|
33
|
+
ch.on_extended_data do |c, type, data|
|
34
|
+
print data
|
35
|
+
end
|
36
|
+
|
37
|
+
ch.on_close { puts "Remote Task Completed" }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module ExecRemote
|
2
|
+
class Shell
|
3
|
+
class ReadlineFallback #:nodoc:
|
4
|
+
HISTORY = []
|
5
|
+
|
6
|
+
def self.readline(prompt)
|
7
|
+
STDOUT.print(prompt)
|
8
|
+
STDOUT.flush
|
9
|
+
STDIN.gets
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def reader
|
14
|
+
@reader ||= begin
|
15
|
+
require 'readline'
|
16
|
+
Readline
|
17
|
+
rescue LoadError
|
18
|
+
ReadlineFallback
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def read_line
|
23
|
+
loop do
|
24
|
+
command = reader.readline("> ")
|
25
|
+
|
26
|
+
if command.nil?
|
27
|
+
command = "exit"
|
28
|
+
else
|
29
|
+
command.strip!
|
30
|
+
end
|
31
|
+
|
32
|
+
unless command.empty?
|
33
|
+
reader::HISTORY << command
|
34
|
+
return command
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/exec_remote.rb
ADDED
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: exec_remote
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Selvakumar Natesan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-03 00:00:00 +05:30
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: net-ssh
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Exec Remote is a simple utility to run tests/build against your development code in a remote machine without checking in to a repository. It sync ups your code in local and remote machine with rsync and the commands are executed in remote machine via SSH
|
26
|
+
email: k.n.selvakumar@gmail.com
|
27
|
+
executables:
|
28
|
+
- exec_remote
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- CHANGELOG.rdoc
|
33
|
+
- README.rdoc
|
34
|
+
- lib/exec_remote.rb
|
35
|
+
- lib/exec_remote/cli.rb
|
36
|
+
- lib/exec_remote/configuration.rb
|
37
|
+
- lib/exec_remote/remote_executor.rb
|
38
|
+
- lib/exec_remote/shell.rb
|
39
|
+
files:
|
40
|
+
- CHANGELOG.rdoc
|
41
|
+
- Manifest
|
42
|
+
- README.rdoc
|
43
|
+
- Rakefile
|
44
|
+
- bin/exec_remote
|
45
|
+
- lib/exec_remote.rb
|
46
|
+
- lib/exec_remote/cli.rb
|
47
|
+
- lib/exec_remote/configuration.rb
|
48
|
+
- lib/exec_remote/remote_executor.rb
|
49
|
+
- lib/exec_remote/shell.rb
|
50
|
+
- spec/functional/basic_spec.rb
|
51
|
+
- exec_remote.gemspec
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: https://github.com/selvakn/exec_remote
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options:
|
58
|
+
- --line-numbers
|
59
|
+
- --inline-source
|
60
|
+
- --title
|
61
|
+
- Exec_remote
|
62
|
+
- --main
|
63
|
+
- README.rdoc
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "1.2"
|
77
|
+
version:
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project: exec_remote
|
81
|
+
rubygems_version: 1.3.4
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Exec Remote is a simple utility to run tests/build against your development code in a remote machine without checking in to a repository. It sync ups your code in local and remote machine with rsync and the commands are executed in remote machine via SSH
|
85
|
+
test_files: []
|
86
|
+
|