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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/octosh/cli.rb', line 19
def self.start
options = {}
options[:default_user] = "root"
options[:password_prompt] = true
options[:uniform_password] = false
options[:forward_agent] = false
options[:interactive] = false
optparse = OptionParser.new do|opts|
opts.banner = "Usage: octosh [options] [octo config file]"
opts.on('-c', '--config FILE', 'Octo config file') do |file|
options[:config] = file
end
opts.on('-i', '--interactive', 'Interactive shell prompt') do
options[:interactive] = true
end
opts.on('-b', '--bash COMMAND', 'Explicitly define a command(s) to run on all hosts (Requires --hosts switch)') do |bash|
options[:bash] = bash
end
opts.on('-s', '--script SCRIPT', 'Path to script to run on all hosts (Requires --hosts switch)') do |script|
options[:script] = script
end
opts.on('-r', '--hosts USER@HOST,USER@HOST', Array, 'Lists of hosts to use when using inline execution (with -b or -s switches)') do |list|
options[:hosts] = list
end
opts.on('-u', '--user USER', 'User to use when a user isn\'t defined in the --hosts list (ie. just IP address)') do |user|
options[:default_user] = user
end
opts.on('-p', '--uniform-password', 'Uniform password') do
options[:uniform_password] = true
end
opts.on('--forward-agent', 'Forward Agent') do
options[:forward_agent] = true
end
opts.on_tail('-h', '--help', 'Display this screen' ) do
puts opts
exit
end
end.parse!
if not ARGV.empty? and not options[:config]
puts "Using config file"
options[:config] = ARGV[0]
options[:mode] = Octosh::CLI::MODE::CONFIG
elsif ARGV.empty? and options[:config]
puts "Using config file"
options[:mode] = Octosh::CLI::MODE::CONFIG
elsif not ARGV.empty? and options[:config]
puts "Two config files specified (#{options[:config]} and #{ARGV[0]}), using explicit config file (#{options[:config]})"
options[:mode] = Octosh::CLI::MODE::CONFIG
elsif options[:interactive]
puts "Interactive mode"
options[:mode] = Octosh::CLI::MODE::INTERACTIVE
shell = Octosh::Shell.new(options[:hosts], options)
shell.start
elsif (options[:bash] or options[:script]) and options[:hosts]
puts "Using inline execution"
options[:mode] = Octosh::CLI::MODE::INLINE
if options[:bash] and options[:script]
"Error -- Cannot specify both an inline command to run (-b) and a script file (-s)"
exit
elsif options[:bash]
puts "Inline bash"
self.inline_bash(options[:hosts], options[:bash], options[:default_user], options)
elsif options[:script]
puts "Call script on each server"
self.exec_script(options[:hosts], options[:script], options[:default_user], options)
else
"Error -- Something broke"
exit
end
else
puts "Error -- Must either provide an Octo config file or arguments for inline execution (--hosts along with -b or -s)"
exit
end
end
|