+
+ trap_signals
+ end
+
+ # Determine (if possible) a valid path to a CA certificate bundle.
+ def default_ssl_ca_file
+ [ '/etc/ssl/certs/ca-certificates.crt', # Ubuntu/Debian
+ '/etc/ssl/certs/ca-bundle.crt', # Amazon Linux
+ '/etc/ssl/ca-bundle.pem', # OpenSUSE
+ '/etc/pki/tls/certs/ca-bundle.crt' # Fedora/RHEL
+ ].find do |file|
+ File.readable? file
+ end
+ end
+
+ def default_ssl_ca_path
+ file = default_ssl_ca_file
+ File.dirname file if file
+ end
+
+ # Determine if tokyocabinet is installed, if it is use it as a default.
+ def default_db
+ begin
+ require 'tokyocabinet'
+ return 'tc'
+ rescue LoadError
+ return 'dbm'
+ end
+ end
+
+ def repopulate_botclass_directory
+ template_dir = File.join Config::datadir, 'templates'
+ if FileTest.directory? @botclass
+ # compare the templates dir with the current botclass dir, filling up the
+ # latter with any missing file. Sadly, FileUtils.cp_r doesn't have an
+ # :update option, so we have to do it manually.
+ # Note that we use the */** pattern because we don't want to match
+ # keywords.rbot, which gets deleted on load and would therefore be missing
+ # always
+ missing = Dir.chdir(template_dir) { Dir.glob('*/**') } - Dir.chdir(@botclass) { Dir.glob('*/**') }
+ missing.map do |f|
+ dest = File.join(@botclass, f)
+ FileUtils.mkdir_p(File.dirname(dest))
+ FileUtils.cp File.join(template_dir, f), dest
+ end
+ else
+ log "no #{@botclass} directory found, creating from templates..."
+ if FileTest.exist? @botclass
+ error "file #{@botclass} exists but isn't a directory"
+ exit 2
+ end
+ FileUtils.cp_r template_dir, @botclass
+ end
+ end
+
+ # Return a path under the current botclass by joining the mentioned
+ # components. The components are automatically converted to String
+ def path(*components)
+ File.join(@botclass, *(components.map {|c| c.to_s}))
+ end
+
+ def setup_plugins_path
+ plugdir_default = File.join(Config::datadir, 'plugins')
+ plugdir_local = File.join(@botclass, 'plugins')
+ Dir.mkdir(plugdir_local) unless File.exist?(plugdir_local)
+
+ @plugins.clear_botmodule_dirs
+ @plugins.add_core_module_dir(File.join(Config::coredir, 'utils'))
+ @plugins.add_core_module_dir(Config::coredir)
+ if FileTest.directory? plugdir_local
+ @plugins.add_plugin_dir(plugdir_local)
+ else
+ warning "local plugin location #{plugdir_local} is not a directory"
+ end
+
+ @config['plugins.path'].each do |_|
+ path = _.sub(/^\(default\)/, plugdir_default)
+ @plugins.add_plugin_dir(path)
+ end