#!/usr/local/bin/ruby if RUBY_VERSION < "1.8.1" puts "Pimki requires Ruby 1.8.1+" exit end # Handle rubygems support & loading libraries: {{{ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "libraries") begin require 'rubygems' require_gem 'madeleine' require_gem 'redcloth', '~> 2.0.11' require_gem 'rubyzip' require_gem 'bluecloth' rescue LoadError # no rubygems, so load from the libraries directory require 'redcloth' require 'bluecloth' end # }}} # Handle command-line options: {{{ require 'optparse' cdir = File.expand_path(File.dirname(__FILE__)) %w( /libraries/ /app/models /app/controllers ).each { |dir| $:.unshift(cdir + dir) } %w( web_controller_server action_controller_servlet wiki_service wiki ).each { |lib| require lib } fork_available = true begin exit unless fork rescue NotImplementedError fork_available = false end begin pdflatex_available = system "pdflatex -version" rescue Errno::ENOENT pdflatex_available = false end OPTIONS = { :server_type => fork_available ? Daemon : SimpleServer, :port => 2500, :storage => "#{Dir.pwd}/storage", :pdflatex => pdflatex_available } ARGV.options do |opts| script_name = File.basename($0) opts.banner = "Usage: ruby #{script_name} [options]" opts.separator "" opts.on("-p", "--port=port", Integer, "Runs Instiki on the specified port.", "Default: 2500") { |OPTIONS[:port]| } opts.on("-s", "--simple", "--simple-server", "Forces Instiki not to run as a Daemon if fork is available." ) { OPTIONS[:server_type] = SimpleServer } opts.on("-t", "--storage=storage", String, "Makes Instiki use the specified directory for storage.", "Default: [cwd]/storage/[port]") { |OPTIONS[:storage]| } opts.separator "" opts.on("-h", "--help", "Show this help message.") { puts opts; exit } opts.parse! end Socket.do_not_reverse_lookup = true #}}} # Start the application: {{{ storage_dir = OPTIONS[:storage] + "/" + OPTIONS[:port].to_s require 'fileutils' FileUtils.mkdir_p(storage_dir) WikiService.storage_path = storage_dir WikiController.template_root = "#{cdir}/app/views/" trap "INT" do WebControllerServer::the_active_server.shutdown end trap "TERM" do WebControllerServer::the_active_server.shutdown end WebControllerServer.new(OPTIONS[:port], OPTIONS[:server_type], "#{cdir}/app/controllers/") # }}} # jEdit :folding=explicit:collapseFolds=1: