1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-30 08:53:05 +00:00
mpw/mpw-ssh

91 lines
2.1 KiB
Text
Raw Normal View History

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'
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)
2014-09-12 06:41:27 +00:00
require "#{APP_ROOT}/lib/UI/CliSSH"
require "#{APP_ROOT}/lib/Config"
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]
2014-02-01 19:17:55 +00:00
# --------------------------------------------------------- #
# Set local
# --------------------------------------------------------- #
2014-11-16 18:39:38 +00:00
if defined?(I18n.enforce_available_locales)
2014-02-01 19:17:55 +00:00
I18n.enforce_available_locales = true
end
2013-12-30 21:14:29 +00:00
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
2014-11-16 18:39:38 +00:00
I18n.load_path = Dir["#{APP_ROOT}/i18n/cli/*.yml"]
2013-12-30 21:14:29 +00:00
I18n.default_locale = :en
2014-11-16 18:39:38 +00:00
I18n.locale = lang.to_sym
2013-12-26 09:57:03 +00:00
2014-02-01 19:17:55 +00:00
# --------------------------------------------------------- #
# Options
# --------------------------------------------------------- #
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-12-26 17:18:10 +00:00
opts.on("-l", "--login LOGIN", I18n.t('ssh.option.login')) do |login|
options[:login] = login
end
2013-12-26 17:18:10 +00:00
opts.on("-s", "--server SERVER", I18n.t('ssh.option.server')) do |server|
options[:server] = server
end
2013-12-26 17:18:10 +00:00
opts.on("-p", "--port PORT", I18n.t('ssh.option.port')) do |port|
options[:port] = port
end
opts.on('-c', '--config CONFIG', I18n.t('cli.option.config')) do |config|
options[:config] = config
end
2014-01-23 21:32:48 +00:00
opts.on("-h", "--help", I18n.t('ssh.option.help')) do
puts opts
exit 0
end
end.parse!
2014-02-01 19:17:55 +00:00
# --------------------------------------------------------- #
# Main
# --------------------------------------------------------- #
2014-01-29 19:49:39 +00:00
config = MPW::Config.new(options[:config])
2014-02-02 09:16:10 +00:00
check_error = config.checkconfig
2014-01-23 21:32:48 +00:00
2014-09-07 08:00:46 +00:00
cli = CliSSH.new(config)
2014-01-23 21:32:48 +00:00
cli.login = options[:login]
cli.server = options[:server]
cli.port = options[:port]
search = ARGV[0]
2013-12-26 17:20:15 +00:00
2014-01-23 21:32:48 +00:00
# Setup a new config
2014-11-16 18:39:38 +00:00
if not check_error
2014-01-23 21:32:48 +00:00
cli.setup(lang)
elsif 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
2014-01-23 22:04:13 +00:00
else
2014-02-02 09:16:10 +00:00
cli.decrypt
cli.sync
2014-01-23 22:04:13 +00:00
cli.ssh(search)
2013-08-06 20:24:09 +00:00
end
2014-02-02 09:16:10 +00:00
cli = nil
2013-08-06 20:24:09 +00:00
exit 0