2013-08-06 20:24:09 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
# author: nishiki
|
|
|
|
# mail: nishiki@yaegashi.fr
|
|
|
|
# info: a simple script who manage your passwords
|
|
|
|
|
|
|
|
require 'rubygems'
|
2013-08-24 22:55:11 +00:00
|
|
|
require 'optparse'
|
2013-08-06 20:24:09 +00:00
|
|
|
require 'pathname'
|
2013-12-26 09:57:03 +00:00
|
|
|
require 'locale'
|
|
|
|
require 'i18n'
|
2013-08-06 20:24:09 +00:00
|
|
|
|
|
|
|
APP_ROOT = File.dirname(Pathname.new(__FILE__).realpath)
|
2013-09-04 17:48:06 +00:00
|
|
|
require "#{APP_ROOT}/lib/CliSSH.rb"
|
2013-08-06 20:24:09 +00:00
|
|
|
|
2013-12-26 09:57:03 +00:00
|
|
|
lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1]
|
|
|
|
|
|
|
|
if !File.exist?("#{APP_ROOT}/i18n/#{lang}.yml")
|
|
|
|
lang = 'en'
|
|
|
|
end
|
2013-12-30 20:00:07 +00:00
|
|
|
I18n.load_path = Dir["#{APP_ROOT}/i18n/*.yml"]
|
2013-12-26 09:57:03 +00:00
|
|
|
I18n.locale = lang.to_sym
|
|
|
|
|
2013-12-27 09:58:59 +00:00
|
|
|
|
2013-08-24 22:55:11 +00:00
|
|
|
options = {}
|
|
|
|
OptionParser.new do |opts|
|
2013-12-26 17:18:10 +00:00
|
|
|
opts.banner = "#{I18n.t('ssh.option.usage')}: mpw-ssh SEARCH [options]"
|
2013-08-24 22:55:11 +00:00
|
|
|
|
2013-12-26 17:18:10 +00:00
|
|
|
opts.on("-l", "--login LOGIN", I18n.t('ssh.option.login')) do |login|
|
2013-12-30 19:15:00 +00:00
|
|
|
options[:login] = login
|
2013-08-24 22:55:11 +00:00
|
|
|
end
|
|
|
|
|
2013-12-26 17:18:10 +00:00
|
|
|
opts.on("-s", "--server SERVER", I18n.t('ssh.option.server')) do |server|
|
2013-12-30 19:15:00 +00:00
|
|
|
options[:server] = server
|
2013-08-24 22:55:11 +00:00
|
|
|
end
|
|
|
|
|
2013-12-26 17:18:10 +00:00
|
|
|
opts.on("-p", "--port PORT", I18n.t('ssh.option.port')) do |port|
|
2013-12-30 19:15:00 +00:00
|
|
|
options[:port] = port
|
|
|
|
end
|
|
|
|
|
|
|
|
opts.on('-c', '--config CONFIG', I18n.t('cli.option.config')) do |config|
|
|
|
|
options[:config] = config
|
2013-08-24 22:55:11 +00:00
|
|
|
end
|
|
|
|
|
2013-12-26 17:18:10 +00:00
|
|
|
opts.on("-h", "--help", I18n.t('ssh.option.help')) do |b|
|
2013-08-24 22:55:11 +00:00
|
|
|
puts opts
|
|
|
|
exit 0
|
|
|
|
end
|
|
|
|
end.parse!
|
|
|
|
|
2013-12-30 19:15:00 +00:00
|
|
|
cli = CliSSH.new(lang, options[:config])
|
|
|
|
cli.login = options[:login]
|
|
|
|
cli.server = options[:server]
|
|
|
|
cli.port = options[:port]
|
|
|
|
|
|
|
|
search = ARGV[0]
|
2013-12-26 17:20:15 +00:00
|
|
|
|
2013-08-24 22:55:11 +00:00
|
|
|
if ARGV.length < 1
|
2013-12-26 17:18:10 +00:00
|
|
|
puts "#{I18n.t('ssh.option.usage')}: mpw-ssh SEARCH [options]"
|
2013-08-06 20:24:09 +00:00
|
|
|
exit 2
|
|
|
|
end
|
|
|
|
|
|
|
|
cli.ssh(search)
|
|
|
|
|
|
|
|
exit 0
|