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

61 lines
1.4 KiB
Text
Raw Normal View History

2014-01-10 16:55:05 +00:00
#!/usr/bin/ruby
# author: nishiki
# mail: nishiki@yaegashi.fr
# info: a simple script who manage your passwords
require 'rubygems'
require 'optparse'
require 'pathname'
2014-01-10 21:36:51 +00:00
require 'locale'
require 'i18n'
2014-01-10 16:55:05 +00:00
APP_ROOT = File.dirname(Pathname.new(__FILE__).realpath)
require "#{APP_ROOT}/lib/Server.rb"
2014-01-10 21:36:51 +00:00
lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1]
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
I18n.load_path = Dir["#{APP_ROOT}/i18n/*.yml"]
I18n.default_locale = :en
I18n.locale = lang.to_sym
2014-01-10 16:55:05 +00:00
options = {}
OptionParser.new do |opts|
2014-01-10 21:36:51 +00:00
opts.banner = "#{I18n.t('server.option.usage')}: mpw-server -c CONFIG [options]"
2014-01-10 16:55:05 +00:00
2014-01-10 21:36:51 +00:00
opts.on("-c", "--config CONFIG", I18n.t('server.option.config')) do |config|
2014-01-10 16:55:05 +00:00
options[:config] = config
end
2014-01-10 21:36:51 +00:00
opts.on("-t", "--checkconfig", I18n.t('server.option.checkconfig')) do |b|
2014-01-10 16:55:05 +00:00
options[:checkconfig] = b
end
2014-01-10 21:36:51 +00:00
opts.on("-s", "--setup", I18n.t('server.option.setup')) do |b|
2014-01-10 16:55:05 +00:00
options[:setup] = b
end
2014-01-10 21:36:51 +00:00
opts.on("-h", "--help", I18n.t('server.option.help')) do |b|
2014-01-10 16:55:05 +00:00
puts opts
exit 0
end
end.parse!
2014-01-10 21:36:51 +00:00
if options[:config].nil? || options[:config].empty?
puts "#{I18n.t('server.option.usage')}: mpw-server -c CONFIG [options]"
exit 2
end
2014-01-10 16:55:05 +00:00
server = Server.new
if options[:checkconfig]
server.checkconfig(options[:config])
elsif options[:setup]
server.setup(options[:config])
else
server.checkconfig(options[:config])
server.start()
end
exit 0