#!/usr/bin/ruby require 'rubygems' require 'optparse' require 'i2cssh' i2_options, ssh_options, servers = {}, [], [] optparse = OptionParser.new do |opts| opts.banner = "Usage: #{File.basename(__FILE__)} [options]" # SSH options opts.on '-A', '--forward-agent', 'Enable SSH agent forwarding' do ssh_options << '-A' end opts.on '-l', '--login LOGIN', 'SSH login name' do |u| ssh_options << "-l #{u}" end # iTerm2 options opts.on '-F', '--fullscreen', 'Make the window fullscreen' do i2_options[:fullscreen] = true end opts.on '-C', '--columns COLUMNS', Integer, 'Number of columns (rows will be calculated)' do |c| i2_options[:columns] = c end opts.on '-R', '--rows ROWS', Integer, 'Number of rows (columns will be calculated)' do |r| if i2_options[:columns] puts "ERROR: -C and -R can't be used at the same time" puts optparse.help exit else i2_options[:rows] = r end end opts.on '-b', '--broadcast', 'Start with broadcast input (DANGEROUS!)' do i2_options[:broadcast] = true end # Hosts opts.on '-f', '--file FILE', 'Cluster file (one hostname per line)' do |f| servers += File.read(f).split "\n" end opts.on '-c', '--cluster CLUSTERNAME', 'Name of the cluster specified in ~/.i2csshrc' do |c| require 'yaml' config_hash = YAML.load File.read File.expand_path '~/.i2csshrc' cluster = config_hash["clusters"][c] if cluster servers += cluster else puts "ERROR: unknown cluster #{c}" puts optparse.help exit 1 end end opts.on '-m', '--machines a,b,c', Array, 'Comma-separated list of hosts' do |h| servers += h end end optparse.parse! if servers.empty? puts "ERROR: no servers given" puts optparse.help exit end I2Cssh.new servers, ssh_options, i2_options