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

79 lines
1.8 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)
2014-09-12 06:41:27 +00:00
require "#{APP_ROOT}/lib/Server.rb"
2014-01-10 16:55:05 +00:00
2014-02-01 19:17:55 +00:00
# --------------------------------------------------------- #
# Set local
# --------------------------------------------------------- #
2014-01-10 21:36:51 +00:00
lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1]
2014-11-16 18:46:21 +00:00
if defined?(I18n.enforce_available_locales)
2014-02-01 19:17:55 +00:00
I18n.enforce_available_locales = true
end
2014-01-10 21:36:51 +00:00
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
2014-01-25 17:40:47 +00:00
I18n.load_path = Dir["#{APP_ROOT}/i18n/server/*.yml"]
2014-01-10 21:36:51 +00:00
I18n.default_locale = :en
I18n.locale = lang.to_sym
2014-02-01 19:17:55 +00:00
# --------------------------------------------------------- #
# Options
# --------------------------------------------------------- #
2014-01-10 16:55:05 +00:00
options = {}
OptionParser.new do |opts|
2014-01-25 17:40:47 +00:00
opts.banner = "#{I18n.t('option.usage')}: mpw-server -c CONFIG [options]"
2014-01-10 16:55:05 +00:00
2014-01-25 17:40:47 +00:00
opts.on("-c", "--config CONFIG", I18n.t('option.config')) do |config|
2014-01-10 16:55:05 +00:00
options[:config] = config
end
2014-01-25 17:40:47 +00:00
opts.on("-t", "--checkconfig", I18n.t('option.checkconfig')) do |b|
2014-01-10 16:55:05 +00:00
options[:checkconfig] = b
end
2014-01-25 17:40:47 +00:00
opts.on("-s", "--setup", I18n.t('option.setup')) do |b|
2014-01-10 16:55:05 +00:00
options[:setup] = b
end
2014-01-25 17:40:47 +00:00
opts.on("-h", "--help", I18n.t('option.help')) do |b|
2014-01-10 16:55:05 +00:00
puts opts
exit 0
end
end.parse!
2014-02-01 19:17:55 +00:00
# --------------------------------------------------------- #
# Main
# --------------------------------------------------------- #
2014-11-16 18:46:21 +00:00
if options[:config].nil? or options[:config].empty?
2014-01-25 17:40:47 +00:00
puts "#{I18n.t('option.usage')}: mpw-server -c CONFIG [options]"
2014-01-10 21:36:51 +00:00
exit 2
end
2014-04-27 16:23:28 +00:00
server = MPW::Server.new
2014-01-10 16:55:05 +00:00
if options[:checkconfig]
server.checkconfig(options[:config])
elsif options[:setup]
server.setup(options[:config])
else
2014-01-25 10:35:12 +00:00
if server.checkconfig(options[:config])
2014-02-01 19:17:55 +00:00
server.start
2014-01-25 10:35:12 +00:00
end
2014-01-10 16:55:05 +00:00
end
2014-02-01 19:17:55 +00:00
server = nil
2014-01-10 16:55:05 +00:00
exit 0