mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-23 22:03:05 +00:00
78 lines
1.8 KiB
Ruby
Executable file
78 lines
1.8 KiB
Ruby
Executable file
#!/usr/bin/ruby
|
|
# author: nishiki
|
|
# mail: nishiki@yaegashi.fr
|
|
# info: a simple script who manage your passwords
|
|
|
|
require 'rubygems'
|
|
require 'optparse'
|
|
require 'pathname'
|
|
require 'locale'
|
|
require 'i18n'
|
|
|
|
APP_ROOT = File.dirname(Pathname.new(__FILE__).realpath)
|
|
require "#{APP_ROOT}/lib/Server.rb"
|
|
|
|
# --------------------------------------------------------- #
|
|
# Set local
|
|
# --------------------------------------------------------- #
|
|
|
|
lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1]
|
|
|
|
if defined?(I18n.enforce_available_locales)
|
|
I18n.enforce_available_locales = true
|
|
end
|
|
|
|
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
|
|
I18n.load_path = Dir["#{APP_ROOT}/i18n/server/*.yml"]
|
|
I18n.default_locale = :en
|
|
I18n.locale = lang.to_sym
|
|
|
|
# --------------------------------------------------------- #
|
|
# Options
|
|
# --------------------------------------------------------- #
|
|
|
|
options = {}
|
|
OptionParser.new do |opts|
|
|
opts.banner = "#{I18n.t('option.usage')}: mpw-server -c CONFIG [options]"
|
|
|
|
opts.on("-c", "--config CONFIG", I18n.t('option.config')) do |config|
|
|
options[:config] = config
|
|
end
|
|
|
|
opts.on("-t", "--checkconfig", I18n.t('option.checkconfig')) do |b|
|
|
options[:checkconfig] = b
|
|
end
|
|
|
|
opts.on("-s", "--setup", I18n.t('option.setup')) do |b|
|
|
options[:setup] = b
|
|
end
|
|
|
|
opts.on("-h", "--help", I18n.t('option.help')) do |b|
|
|
puts opts
|
|
exit 0
|
|
end
|
|
end.parse!
|
|
|
|
# --------------------------------------------------------- #
|
|
# Main
|
|
# --------------------------------------------------------- #
|
|
|
|
if options[:config].nil? or options[:config].empty?
|
|
puts "#{I18n.t('option.usage')}: mpw-server -c CONFIG [options]"
|
|
exit 2
|
|
end
|
|
|
|
server = MPW::Server.new
|
|
|
|
if options[:checkconfig]
|
|
server.checkconfig(options[:config])
|
|
elsif options[:setup]
|
|
server.setup(options[:config])
|
|
else
|
|
if server.checkconfig(options[:config])
|
|
server.start
|
|
end
|
|
end
|
|
|
|
server = nil
|
|
exit 0
|
|
|