-
Notifications
You must be signed in to change notification settings - Fork 1
/
ec2-scp
executable file
·53 lines (44 loc) · 1.25 KB
/
ec2-scp
1
2
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
42
43
44
45
46
47
48
49
50
51
52
53
#! /usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "fog"
require "fileutils"
require 'trollop'
require 'yaml'
require_relative 'environment.rb'
require_relative 'menu.rb'
require_relative 'ssh_instance.rb'
require_relative 'scp_instance.rb'
include Environment
include Menu
SUB_COMMANDS = %w(get put)
opts = Trollop::options do
opt :environment, "", :type => :string, :default => ""
opt :regex, "", :type => :string
opt :user, "", :type => :string
stop_on SUB_COMMANDS
end
cmd = ARGV.shift # get the subcommand
cmd_opts = case cmd.downcase
when "get" # parse delete options
Trollop::options do
opt :get, "get the file", :default => true
end
when "put" # parse copy options
Trollop::options do
opt :put, "puts the file", :default => true
end
else
Trollop::die "unknown subcommand #{cmd.inspect}"
end
environment = opts[:environment] || get_environment
settings = set_environment(environment)
regex = opts[:regex]
instance = ScpInstance.get(environment, settings, regex)
instance.user = opts[:user]
instance.remote_path = get_path('remote')
instance.local_path = get_path('local')
ssh_cmd = instance.get_cmd if !cmd_opts[:get].nil?
ssh_cmd = instance.put_cmd if !cmd_opts[:put].nil?
puts ssh_cmd
exec(ssh_cmd)