end\r
end\r
\r
-ScriptDir = File.dirname(__FILE__)\r
-Dir.glob(ScriptDir + "/lib/*.rb").each {|rb|\r
- require rb\r
-}\r
-\r
-Windows::Authorization.runas_admin\r
-\r
-home = File.expand_path(ENV["PACKAGE_HOME"])\r
-host = Socket.gethostbyname(Socket.gethostname).first\r
-options = {\r
- :interact => true,\r
- :home => home,\r
- :fqdn_or_ipaddr => host.include?(".") ? host : IPSocket.getaddress(host),\r
- :apache_root => File.join(home, "apache"),\r
- :redmine_root => File.join(home, "redmine"),\r
- :opends_root => File.join(home, "opends"),\r
- :opends_manager_dn => "cn=Directory Manager",\r
- :opends_manager_password => Account.random_password(10)\r
-}\r
-options[:apache_host] = options[:fqdn_or_ipaddr]\r
-\r
-config = [\r
- {:name => :apache_name, :default => "Apache"},\r
- {:name => :apache_port, :type => :int, :default => 80},\r
- {:name => :redmine_name, :default => "Redmine"},\r
- {:name => :redmine_port, :type => :int, :default => 8000},\r
- {:name => :jenkins_name, :default => "Jenkins"},\r
- {:name => :jenkins_port, :type => :int, :default => 8001},\r
-\r
- {:name => :ldap_setting, :type => :bool,\r
- :message => "Use external LDAP server? (y/n): "},\r
- {:name => :opends_name, :default => "OpenDS", :parent => :ldap_setting, :if => false},\r
- {:name => :opends_port, :type => :int, :default => 389, :parent => :ldap_setting, :if => false},\r
- {:name => :opends_admin_port, :type => :int, :default => 8002, :parent => :ldap_setting, :if => false},\r
- {:name => :opends_base_dn, :default => "dc=redminele,dc=local", :parent => :ldap_setting, :if => false},\r
-\r
- {:name => :ldap_host, :default => "localhost", :parent => :ldap_setting, :if => true},\r
- {:name => :ldap_port, :type => :int, :default => 389, :parent => :ldap_setting, :if => true},\r
- {:name => :ldap_base_dn, :parent => :ldap_setting, :if => true, :message => "Enter LDAP Base DN (ex. ou=users,dc=local): "},\r
- {:name => :ldap_anonymous, :type => :bool, :message => "LDAP server permits anonymous bind? ([y]/n): ", :default => true, :parent => :ldap_setting, :if => true},\r
- {:name => :ldap_bind_dn, :message => "Enter LDAP bind DN (ex. uid=xxx,ou=users,dc=local): ", :parent => :ldap_anonymous, :if => false},\r
- {:name => :ldap_bind_password, :message => "Enter LDAP bind password: ", :parent => :ldap_anonymous, :if => false, :type => :password},\r
- {:name => :ldap_user_attribute, :default => "uid", :parent => :ldap_setting, :if => true},\r
- {:name => :ldap_first_name_attribute, :default => "givenName", :parent => :ldap_setting, :if => true},\r
- {:name => :ldap_last_name_attribute, :default => "sn", :parent => :ldap_setting, :if => true},\r
- {:name => :ldap_mail_attribute, :default => "mail", :parent => :ldap_setting, :if => true},\r
-\r
- {:name => :admin_account},\r
- {:name => :admin_password, :type => :password},\r
- {:name => :admin_mail, :type => :mail},\r
- {:name => :admin_first_name},\r
- {:name => :admin_last_name},\r
-\r
- {:name => :smtp_setting, :type => :bool,\r
- :message => "Use redmine email notification? (y/n): "},\r
- {:name => :mail_sender_address, :parent => :smtp_setting, :if => true, :type => :mail},\r
- {:name => :smtp_host, :parent => :smtp_setting, :if => true},\r
- {:name => :smtp_port, :parent => :smtp_setting,:type => :int, :default => 25, :if => true},\r
- {:name => :smtp_domain, :parent => :smtp_setting, :if => true,\r
- :default => options[:fqdn_or_ipaddr]},\r
- {:name => :smtp_auth, :parent => :smtp_setting, :if => true, :type => :bool,\r
- :message => "Use smtp auth? (y/n): "},\r
- {:name => :smtp_user, :parent => :smtp_auth, :if => true},\r
- {:name => :smtp_password, :parent => :smtp_auth, :if => true, :type => :password}\r
-]\r
-\r
-option_keys = []\r
-config_hash = {}\r
-config.each {|h|\r
- option_keys.push(key = h[:name])\r
- name = key.to_s\r
-\r
- if h[:message].nil?\r
- default = h[:default]\r
- default = default.nil? ? "" : " (default: #{default})"\r
- h[:message] = "Enter #{name.gsub('_', ' ')}#{default}: "\r
- end\r
+begin\r
+ ScriptDir = File.dirname(__FILE__)\r
+ Dir.glob(ScriptDir + "/lib/*.rb").each {|rb|\r
+ require rb\r
+ }\r
+\r
+ Windows::Authorization.runas_admin\r
\r
- optname = name.gsub('_', '-')\r
- h[:option_name] = (h[:type] == :bool) ?\r
- "--[no-]" + optname : "--#{optname}=VAL"\r
- h[:class] = Integer if h[:type] == :int\r
- \r
- config_hash[key] = h\r
-}\r
-\r
-OptionParser.new {|opt|\r
- opt.banner = "Usage: install [options] [file|-]"\r
- opt.on('--[no-]interact') {|v| options[:interact] = v}\r
-\r
- option_keys.each {|key|\r
- conf = config_hash[key]\r
- args = conf[:option_name].to_a\r
- args.push conf[:class] if conf[:class]\r
- opt.on(*args) {|v| options[key] = v.toutf8}\r
+ home = File.expand_path(ENV["PACKAGE_HOME"])\r
+ host = Socket.gethostbyname(Socket.gethostname).first\r
+ options = {\r
+ :interact => true,\r
+ :home => home,\r
+ :fqdn_or_ipaddr => host.include?(".") ? host : IPSocket.getaddress(host),\r
+ :apache_root => File.join(home, "apache"),\r
+ :redmine_root => File.join(home, "redmine"),\r
+ :opends_root => File.join(home, "opends"),\r
+ :opends_manager_dn => "cn=Directory Manager",\r
+ :opends_manager_password => Account.random_password(10)\r
}\r
- opt.parse!\r
-}\r
+ options[:apache_host] = options[:fqdn_or_ipaddr]\r
\r
-if config_file = ARGV.first\r
- hash = if config_file == "-"\r
- YAML.load(STDIN.read.toutf8)\r
- else\r
- YAML.load_file(config_file)\r
- end || {}\r
- hash.each {|key, val| options[key.to_sym] = val} if hash.is_a?(Hash)\r
- options[:interact] = false\r
-end\r
+ config = [\r
+ {:name => :apache_name, :default => "Apache"},\r
+ {:name => :apache_port, :type => :int, :default => 80},\r
+ {:name => :redmine_name, :default => "Redmine"},\r
+ {:name => :redmine_port, :type => :int, :default => 8000},\r
+ {:name => :jenkins_name, :default => "Jenkins"},\r
+ {:name => :jenkins_port, :type => :int, :default => 8001},\r
+\r
+ {:name => :ldap_setting, :type => :bool,\r
+ :message => "Use external LDAP server? (y/n): "},\r
+ {:name => :opends_name, :default => "OpenDS", :parent => :ldap_setting, :if => false},\r
+ {:name => :opends_port, :type => :int, :default => 389, :parent => :ldap_setting, :if => false},\r
+ {:name => :opends_admin_port, :type => :int, :default => 8002, :parent => :ldap_setting, :if => false},\r
+ {:name => :opends_base_dn, :default => "dc=redminele,dc=local", :parent => :ldap_setting, :if => false},\r
\r
-def bind_check(options)\r
- LDAP.setup_connection(options)\r
- unless LDAP.check_connection\r
- %w[ldap_host ldap_port ldap_anonymous ldap_bind_dn ldap_bind_password\r
- ].each {|key| options.delete(key.to_sym)}\r
- return false\r
+ {:name => :ldap_host, :default => "localhost", :parent => :ldap_setting, :if => true},\r
+ {:name => :ldap_port, :type => :int, :default => 389, :parent => :ldap_setting, :if => true},\r
+ {:name => :ldap_base_dn, :parent => :ldap_setting, :if => true, :message => "Enter LDAP Base DN (ex. ou=users,dc=local): "},\r
+ {:name => :ldap_anonymous, :type => :bool, :message => "LDAP server permits anonymous bind? ([y]/n): ", :default => true, :parent => :ldap_setting, :if => true},\r
+ {:name => :ldap_bind_dn, :message => "Enter LDAP bind DN (ex. uid=xxx,ou=users,dc=local): ", :parent => :ldap_anonymous, :if => false},\r
+ {:name => :ldap_bind_password, :message => "Enter LDAP bind password: ", :parent => :ldap_anonymous, :if => false, :type => :password},\r
+ {:name => :ldap_user_attribute, :default => "uid", :parent => :ldap_setting, :if => true},\r
+ {:name => :ldap_first_name_attribute, :default => "givenName", :parent => :ldap_setting, :if => true},\r
+ {:name => :ldap_last_name_attribute, :default => "sn", :parent => :ldap_setting, :if => true},\r
+ {:name => :ldap_mail_attribute, :default => "mail", :parent => :ldap_setting, :if => true},\r
+\r
+ {:name => :admin_account},\r
+ {:name => :admin_password, :type => :password},\r
+ {:name => :admin_mail, :type => :mail},\r
+ {:name => :admin_first_name},\r
+ {:name => :admin_last_name},\r
+\r
+ {:name => :smtp_setting, :type => :bool,\r
+ :message => "Use redmine email notification? (y/n): "},\r
+ {:name => :mail_sender_address, :parent => :smtp_setting, :if => true, :type => :mail},\r
+ {:name => :smtp_host, :parent => :smtp_setting, :if => true},\r
+ {:name => :smtp_port, :parent => :smtp_setting,:type => :int, :default => 25, :if => true},\r
+ {:name => :smtp_domain, :parent => :smtp_setting, :if => true,\r
+ :default => options[:fqdn_or_ipaddr]},\r
+ {:name => :smtp_auth, :parent => :smtp_setting, :if => true, :type => :bool,\r
+ :message => "Use smtp auth? (y/n): "},\r
+ {:name => :smtp_user, :parent => :smtp_auth, :if => true},\r
+ {:name => :smtp_password, :parent => :smtp_auth, :if => true, :type => :password}\r
+ ]\r
+\r
+ option_keys = []\r
+ config_hash = {}\r
+ config.each {|h|\r
+ option_keys.push(key = h[:name])\r
+ name = key.to_s\r
+\r
+ if h[:message].nil?\r
+ default = h[:default]\r
+ default = default.nil? ? "" : " (default: #{default})"\r
+ h[:message] = "Enter #{name.gsub('_', ' ')}#{default}: "\r
+ end\r
+\r
+ optname = name.gsub('_', '-')\r
+ h[:option_name] = (h[:type] == :bool) ?\r
+ "--[no-]" + optname : "--#{optname}=VAL"\r
+ h[:class] = Integer if h[:type] == :int\r
+ \r
+ config_hash[key] = h\r
+ }\r
+\r
+ OptionParser.new {|opt|\r
+ opt.banner = "Usage: install [options] [file|-]"\r
+ opt.on('--[no-]interact') {|v| options[:interact] = v}\r
+\r
+ option_keys.each {|key|\r
+ conf = config_hash[key]\r
+ args = conf[:option_name].to_a\r
+ args.push conf[:class] if conf[:class]\r
+ opt.on(*args) {|v| options[key] = v.toutf8}\r
+ }\r
+ opt.parse!\r
+ }\r
+\r
+ if config_file = ARGV.first\r
+ hash = if config_file == "-"\r
+ YAML.load(STDIN.read.toutf8)\r
+ else\r
+ YAML.load_file(config_file)\r
+ end || {}\r
+ hash.each {|key, val| options[key.to_sym] = val} if hash.is_a?(Hash)\r
+ options[:interact] = false\r
end\r
- true\r
-end\r
\r
-def admin_check(options)\r
- LDAP.setup_connection(options)\r
- unless LDAP.check_bind(options[:admin_account], options[:admin_password])\r
- %w[ldap_base_dn ldap_user_attribute admin_account admin_password\r
- ].each {|key| options.delete(key.to_sym)}\r
- return false\r
+ def bind_check(options)\r
+ LDAP.setup_connection(options)\r
+ unless LDAP.check_connection\r
+ %w[ldap_host ldap_port ldap_anonymous ldap_bind_dn ldap_bind_password\r
+ ].each {|key| options.delete(key.to_sym)}\r
+ return false\r
+ end\r
+ true\r
end\r
\r
- attrs = LDAP.search_attributes(options[:admin_account])\r
- %w[first_name last_name mail].each {|v|\r
- if value = attrs[options[:"ldap_#{v}_attribute"]]\r
- options[:"admin_#{v}"] = value\r
+ def admin_check(options)\r
+ LDAP.setup_connection(options)\r
+ unless LDAP.check_bind(options[:admin_account], options[:admin_password])\r
+ %w[ldap_base_dn ldap_user_attribute admin_account admin_password\r
+ ].each {|key| options.delete(key.to_sym)}\r
+ return false\r
end\r
- }\r
- true\r
-end\r
\r
-if options[:interact]\r
- option_keys.each {|key|\r
- if options[:ldap_setting]\r
- if key == :ldap_user_attribute && !bind_check(options)\r
- puts "Failed to bind to LDAP server."\r
- retry\r
+ attrs = LDAP.search_attributes(options[:admin_account])\r
+ %w[first_name last_name mail].each {|v|\r
+ if value = attrs[options[:"ldap_#{v}_attribute"]]\r
+ options[:"admin_#{v}"] = value\r
end\r
- if key == :admin_mail && !admin_check(options)\r
- puts "Failed to bind as admin account."\r
- retry\r
+ }\r
+ true\r
+ end\r
+\r
+ if options[:interact]\r
+ option_keys.each {|key|\r
+ if options[:ldap_setting]\r
+ if key == :ldap_user_attribute && !bind_check(options)\r
+ puts "Failed to bind to LDAP server."\r
+ retry\r
+ end\r
+ if key == :admin_mail && !admin_check(options)\r
+ puts "Failed to bind as admin account."\r
+ retry\r
+ end\r
end\r
- end\r
- next unless options[key].nil?\r
-\r
- conf = config_hash[key]\r
- type = conf[:type]\r
- default = conf[:default]\r
- p_key = conf[:parent]\r
- if p_key && options[p_key] != conf[:if]\r
- options[key] = type == :bool ? nil : default\r
- next\r
- end\r
+ next unless options[key].nil?\r
\r
- msg = conf[:message]\r
- options[key] = case type\r
- when :bool\r
- agree(msg) {|q|\r
- q.default = default ? 'y' : 'n' unless default.nil?\r
- q.responses[:ask_on_error] = :question\r
- }\r
- when :int\r
- ask(msg, Integer) {|q|\r
- q.default = default\r
- q.responses[:ask_on_error] = :question\r
- }\r
- when :password\r
- password = ask(msg) {|q| q.echo = '*'}\r
- redo if password.empty?\r
- confirmation = ask("Re-" + msg) {|q| q.echo = '*'}\r
- if password != confirmation\r
- puts "Password doesn't match."\r
- redo\r
+ conf = config_hash[key]\r
+ type = conf[:type]\r
+ default = conf[:default]\r
+ p_key = conf[:parent]\r
+ if p_key && options[p_key] != conf[:if]\r
+ options[key] = type == :bool ? nil : default\r
+ next\r
end\r
- password\r
- when :mail\r
- ask(msg) {|q|\r
- q.validate = /^[\x01-\x7f]+@(\w+\.)+[a-zA-Z]+$/\r
- q.responses[:ask_on_error] = :question\r
- q.responses[:not_valid] = "Invalid email address."\r
- }\r
- else\r
- ans = ask(msg) {|q| q.default = default}.toutf8\r
- redo if ans.empty?\r
- ans\r
+\r
+ msg = conf[:message]\r
+ options[key] = case type\r
+ when :bool\r
+ agree(msg) {|q|\r
+ q.default = default ? 'y' : 'n' unless default.nil?\r
+ q.responses[:ask_on_error] = :question\r
+ }\r
+ when :int\r
+ ask(msg, Integer) {|q|\r
+ q.default = default\r
+ q.responses[:ask_on_error] = :question\r
+ }\r
+ when :password\r
+ password = ask(msg) {|q| q.echo = '*'}\r
+ redo if password.empty?\r
+ confirmation = ask("Re-" + msg) {|q| q.echo = '*'}\r
+ if password != confirmation\r
+ puts "Password doesn't match."\r
+ redo\r
+ end\r
+ password\r
+ when :mail\r
+ ask(msg) {|q|\r
+ q.validate = /^[\x01-\x7f]+@(\w+\.)+[a-zA-Z]+$/\r
+ q.responses[:ask_on_error] = :question\r
+ q.responses[:not_valid] = "Invalid email address."\r
+ }\r
+ else\r
+ ans = ask(msg) {|q| q.default = default}.toutf8\r
+ redo if ans.empty?\r
+ ans\r
+ end\r
+ }\r
+ else\r
+ config_hash.each {|key, conf|\r
+ options[key] = conf[:default] if options[key].nil?\r
+ }\r
+\r
+ if options[:ldap_setting]\r
+ raise "Failed to bind to LDAP server" unless bind_check(options)\r
+ raise "Failed to bind as admin account" unless admin_check(options)\r
end\r
- }\r
-else\r
- config_hash.each {|key, conf|\r
- options[key] = conf[:default] if options[key].nil?\r
- }\r
\r
- if options[:ldap_setting]\r
- raise "Failed to bind to LDAP server" unless bind_check(options)\r
- raise "Failed to bind as admin account" unless admin_check(options)\r
+ config_hash.each {|key, conf|\r
+ next unless options[key].nil?\r
+ p_key = conf[:parent]\r
+ next if p_key && options[p_key].nil?\r
+ raise "#{key.to_s} is not specified" if p_key.nil?\r
+ }\r
end\r
+ options[:apache_host] += ":#{options[:apache_port]}" unless options[:apache_port] == 80\r
\r
- config_hash.each {|key, conf|\r
- next unless options[key].nil?\r
- p_key = conf[:parent]\r
- next if p_key && options[p_key].nil?\r
- raise "#{key.to_s} is not specified" if p_key.nil?\r
+ options.each {|key, value|\r
+ next unless value.is_a?(String)\r
+ next if key.to_s.index("password")\r
+ options[key].strip!\r
}\r
-end\r
-options[:apache_host] += ":#{options[:apache_port]}" unless options[:apache_port] == 80\r
-\r
-options.each {|key, value|\r
- next unless value.is_a?(String)\r
- next if key.to_s.index("password")\r
- options[key].strip!\r
-}\r
-\r
-unless options[:ldap_setting]\r
- options[:ldap_host] = "localhost"\r
- options[:ldap_port] = options[:opends_port]\r
- options[:ldap_base_dn] = options[:opends_base_dn]\r
- options[:ldap_anonymous] = false\r
- options[:ldap_bind_dn] = "uid=#{options[:admin_account]},ou=users,#{options[:ldap_base_dn]}"\r
- options[:ldap_bind_password] = options[:admin_password]\r
- options[:ldap_user_attribute] = "uid"\r
- options[:ldap_first_name_attribute] = "givenName"\r
- options[:ldap_last_name_attribute] = "sn"\r
- options[:ldap_mail_attribute] = "mail"\r
-end\r
\r
-Template.install(options)\r
-OpenDS.install(options) unless options[:ldap_setting]\r
-Redmine.install(options)\r
-system(%Q["#{ScriptDir}/service.bat" install])\r
-Windows::Shortcut.install(options)\r
+ unless options[:ldap_setting]\r
+ options[:ldap_host] = "localhost"\r
+ options[:ldap_port] = options[:opends_port]\r
+ options[:ldap_base_dn] = options[:opends_base_dn]\r
+ options[:ldap_anonymous] = false\r
+ options[:ldap_bind_dn] = "uid=#{options[:admin_account]},ou=users,#{options[:ldap_base_dn]}"\r
+ options[:ldap_bind_password] = options[:admin_password]\r
+ options[:ldap_user_attribute] = "uid"\r
+ options[:ldap_first_name_attribute] = "givenName"\r
+ options[:ldap_last_name_attribute] = "sn"\r
+ options[:ldap_mail_attribute] = "mail"\r
+ end\r
+\r
+ Template.install(options)\r
+ OpenDS.install(options) unless options[:ldap_setting]\r
+ Redmine.install(options)\r
+ system(%Q["#{ScriptDir}/service.bat" install])\r
+ Windows::Shortcut.install(options)\r
+rescue => e\r
+ if options[:interact]\r
+ puts "Error: #{$!}"\r
+ puts "\t" + e.backtrace.join("\n\t")\r
+ ask("Press any key to exit ... ") {|q|\r
+ q.character = true\r
+ q.echo = false\r
+ }\r
+ else\r
+ raise e\r
+ end\r
+end\r