#!/usr/bin/env ruby # This is the main executable file of Adhearsion. # Copyright (c) 2006 Jay Phillips # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies # of the Software, and to permit persons to whom the Software is furnished to do # so, subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. usage = %"Usage: ahn create /path/to/directory ahn start [daemon] [directory] ahn version ahn help|-h|--h|--help|-help ahn install helpername ahn system install systemname ahn search keyword ahn uninstall/remove helpername The helper management system is still under development. Not all of these commands will work. It's coming soon, though! :)" $ADHEARSION_VERSION = "0.7.0" ARGV.unshift 'start' if ARGV.empty? case ARGV.shift when /help|-h|--h|-help|--help/ then puts usage when 'version' then puts "Adhearsion v#{$ADHEARSION_VERSION}" when 'create' require 'fileutils' include FileUtils dest_dir_relative = ARGV.shift || Dir.pwd dest_dir = File.expand_path dest_dir_relative base_dir = File.expand_path File.dirname(__FILE__) from, to = [], [] (Dir["#{base_dir}/{new_projects,docs}/**/*"] + ["#{base_dir}/LICENSE"]).each do |key| value = key[base_dir.length..-1] value.sub! 'new_projects/', '' if value.index 'new_projects/' to << dest_dir + value from << key end #from.each_index { |i| puts "#{from[i]} => #{to[i]}" } # Check overwriting. Abort, Overwrite, Skip from.each_index do |i| if File.directory? from[i] if File.exists? to[i] then puts "Skipping #{to[i]}" else makedirs to[i] end else dir = File.dirname to[i] makedirs dir if !File.exists?(dir) if File.exists? to[i] then puts "Skipping #{to[i]}" else puts "Creating #{to[i]}" copy from[i], to[i] end end end puts <<-MESSAGE Adhearsion project generated! Start your new app with "ahn start #{dest_dir_relative}" For dial plan management, change the appropriate contexts in your /etc/asterisk/extensions.conf file to the following: [your_context_name] exten => _X.,1,AGI(agi://1.2.3.4) ; This IP here To use databases edit config/database.yml for the connection information and, optionally, config/database.rb to change the default database object models. Asterisk Manager interface integration is highly recommended. Edit your /etc/asterisk/manager.conf file and enable the system *securely* with an account for this app. Reload with "asterisk -rx reload manager" and then edit the config/helpers/manager_proxy.yml file appropriately. If you would like a local copy of the Adhearsion wiki, run "rake wiki" in your app folder. Please support the community by contributing documentation improvements by visiting the online, editable version at http://docs.adhearsion.com! MESSAGE when 'start' $DAEMON = false app = Dir.pwd arg = ARGV.shift if arg =~ /daemon(ize)?/ $DAEMON = true arg = ARGV.shift end app = File.expand_path(arg || app) Dir.chdir app puts %{\nStarting Adhearsion v#{$ADHEARSION_VERSION} Written by Jay Phillips of Codemecca LLC, et al. http://adhearsion.com\n\n} %w(rubygems yaml uri open-uri abbrev thread).each do |lib| require lib end $: << File.join(File.dirname(__FILE__), 'lib') $: << 'config' adhearsion_config = File.join('config', 'adhearsion.yml') CONFIG = File.readable?(adhearsion_config) ? YAML.load_file(adhearsion_config) : {} $HUTDOWN = [] class << $HUTDOWN def hook(&block) self << block end def now! puts "Shutting down gracefully." $HUTDOWN.each { |hook| hook.call } exit end end ['INT','TERM'].each do |sig| trap sig do $HUTDOWN.now! end end require 'adhearsion' require 'database' require 'servlet_container' # Load appropriate helpers $HELPERS = {} Contexts::Container.new.run_inside do # Start with compiled helpers class << Object aliens = Dir[File.join('helpers', '*.alien.*')] aliens.each do |f| require 'inline' f = File.basename f config_file = File.join %W(config helpers #{f}.yml) config = File.readable?(config_file) ? YAML.load_file(config_file) : {} if config.delete('enabled') != false lang = f[f.rindex('.')+1..-1] puts "Loading helper #{f} as #{lang.upcase}" $HELPERS[f] = config inline do |builder| builder.send lang, File.read(File.join('helpers', f)) end end end end # Load Ruby helpers Dir[File.join('helpers', '*.rb')].each do |f| name = File.basename(f)[/^[^.]+/] config_file = File.join %W(config helpers #{name}.yml) config = File.readable?(config_file) ? YAML.load_file(config_file) : {} if config.delete('enabled') != false puts "Parsing helper #{name}" $HELPERS[name] = config eval File.read(f) end end end sc = ServletContainer.new $HUTDOWN.hook { sc.shutdown } puts "Dallas, we have liftoff!" sc.server.join else puts "Unrecognized command!", usage end