#!/usr/bin/env ruby require 'rubygems' require 'fileutils' LOCATION_ROOT = File.join(File.dirname(__FILE__), "..") DEST = ARGV[1] || "./marvin" def j(*args); File.join(*args); end def copy(f, t = nil) t = f if t.nil? File.open(j(DEST, t), "w+") do |file| file.puts File.read(j(LOCATION_ROOT, f)) end end puts "Marvin - A Ruby IRC Library / Framework" if ARGV.include?("-h") || ARGV.include?("--help") puts "Usage: marvin create - Creates a marvin directory at name or ./marvin" puts " marvin (in a Marvin dir) - Starts it, equiv. to script/marvin" exit end if ARGV.length >= 1 && !["start", "stop", "run", "restart"].include?(ARGV[0]) if ARGV[0].to_s.downcase != "create" puts "'#{ARGV[0]}' isn't a valid command. - Please use #{__FILE__} --help" exit(1) end if File.exist?(DEST) && File.directory?(DEST) puts "The folder '#{DEST}' already exists." exit(1) end # Generate it. FileUtils.mkdir(DEST) ["log", "tmp", "config", "handlers", "script"].each do |folder| FileUtils.mkdir(j(DEST, folder)) end puts "Writing Settings file" copy "config/settings.yml.sample", "config/settings.yml" puts "Writing Connections file" copy "config/connections.yml.sample", "config/connections.yml" puts "Writing setup.rb" copy "config/setup.rb" puts "Copying start scripts" copy "script/client" copy "script/daemon-runner" FileUtils.chmod 0755, j(DEST, "script/client") FileUtils.chmod 0755, j(DEST, "script/daemon-runner") puts "Copying example handlers" copy "handlers/hello_world.rb" copy "handlers/debug_handler.rb" puts "Done!" elsif ARGV.length >= 1 if !File.exist?("script/daemon-runner") puts "Woops! This isn't a marvin directory." exit(1) end exec "script/daemon-runner #{ARGV.map {|a| a.include?(" ") ? "\"#{a}\"" : a }.join(" ")}" else if !File.exist?("script/client") puts "Woops! This isn't a marvin directory." exit(1) end exec "script/client" end