require 'commands' require 'commands/init/init_model' module Commands module Init class SystemSettingsModel < InitModel inheritable_attributes :unicode, :security_level, :configure_settings # Pick some normal defaults # This basically will upgrade the DB before anything happens to unicode # mode. The default is false, though you probably should use true for # most default 'setups' these days. @unicode = false # The security level is set basically as the first major setting, before # most users are generated, to avoid password mayhem @security_level = 0 # These basically map to 'p4 configure set #{key}=#{value}' @configure_settings = {} #======================================================================== # Internal implementation - don't mess with this #======================================================================== def rank 0 end def self.abstract true end attr_reader :unicode, :security_level, :configure_settings def initialize @unicode = self.class.unicode @security_level = self.class.security_level @configure_settings = self.class.configure_settings end # If the security level is > 0, we generate the super_user first, change # security, then reset the super's password. The p4 connection is # established here with whatever credentials we end up with the super # user as. def execute(p4, super_user) puts 'initializing system settings' set_unicode_mode(p4) set_security_and_super_user(p4, super_user) create_default_protections(p4) end private def set_unicode_mode(p4) if unicode p4.disconnect # Halt any exiting perforce server Commands.kill # Execute the upgrade of the p4d instance Commands.unicode_upgrade # Restart: this assumes the cwd of the init call is the same as the # 'start' call. This is a pretty safe assumption, since our .init # function will call start if it's not running. Commands.start while !Commands.p4d_running? sleep 0.2 end # I'm not sure this should be anything else for the purposes of # initialization p4.charset = 'auto' p4.connect end end def set_security_and_super_user(p4, super_user) # update security mode if needed if security_level > 0 # On some security levels, you *must* reset passwords when updating # even if the base password is strong. super_pwd = super_user.password super_user.password = '' super_user.execute(p4) p4.run('configure', 'set', "security=#{security_level}") p4.user = super_user.login p4.password = super_user.password p4.run_password(super_user.password, super_pwd) super_user.password = super_pwd p4.password = super_user.password p4.run_login else # Just create the user super_user.execute(p4) if super_user.password p4.password = super_user.password p4.run_login end end end def create_default_protections(p4) # This actually will establish the defaults with our super user as the # only entry results = p4.run_protect('-o') end end end end