bin/ezmlm-listd
changeset 12 3cc813140c80
parent 11 7fc2d1713795
child 13 a03c08c289e9
equal deleted inserted replaced
11:7fc2d1713795 12:3cc813140c80
     1 #!/usr/bin/env ruby
       
     2 # 
       
     3 # A startup script for an instance of Ezmlm::ListDaemon.
       
     4 # $Id$
       
     5 # 
       
     6 # Authors:
       
     7 # * Michael Granger <mgranger@laika.com>
       
     8 # * Jeremiah Jordan <jjordan@laika.com>
       
     9 # 
       
    10 
       
    11 BEGIN {
       
    12 	require 'pathname'
       
    13 	basedir = Pathname.new( __FILE__ ).dirname.parent
       
    14 	libdir = basedir + 'lib'
       
    15 	
       
    16 	$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
       
    17 }
       
    18 
       
    19 begin
       
    20 	require 'rubygems'
       
    21 	require 'optparse'
       
    22 	require 'ezmlm/listdaemon'
       
    23 rescue LoadError
       
    24 	unless Object.const_defined?( :Gem )
       
    25 		require 'rubygems'
       
    26 		retry
       
    27 	end
       
    28 	raise
       
    29 end
       
    30 
       
    31 
       
    32 progname = Pathname.new( $0 ).basename
       
    33 opts = Ezmlm::ListDaemon.default_options
       
    34 
       
    35 oparser = OptionParser.new do |oparser|
       
    36 	oparser.accept( Pathname ) {|path| Pathname.new(path) }
       
    37 
       
    38 	oparser.banner = "Usage: #{progname.basename} OPTIONS LISTSDIRECTORY"
       
    39 	oparser.separator 'Version ' + Ezmlm::VERSION
       
    40 
       
    41 	oparser.separator ''
       
    42 	oparser.separator 'Options:'
       
    43 	oparser.on( '--bind ADDRESS', '-b', String, 
       
    44 		"Specify the address to bind to. Defaults to '#{opts.bind_addr}'" ) do |bindaddr|
       
    45 		opts.bind_addr = bindaddr
       
    46 	end
       
    47 
       
    48 	oparser.on( '--port PORTNUMBER', '-p', Integer,
       
    49 		"Specify the port to connect to. Defaults to '#{opts.bind_port}" ) do |portnumber|
       
    50 		opts.bind_port = portnumber
       
    51 	end
       
    52 
       
    53 
       
    54 	oparser.separator ''
       
    55 	oparser.separator 'Other Options:'
       
    56 	oparser.on( '--debug', '-d', FalseClass, "Turn on debugging" ) do
       
    57 		$DEBUG = true
       
    58 		$stderr.puts "Debugging enabled."
       
    59 		opts.debugmode = true
       
    60 	end
       
    61 
       
    62 	oparser.on_tail( '--help', '-h', FalseClass, "Display help for the given command." ) do
       
    63 		$stderr.puts( oparser )
       
    64 		exit!( 0 )
       
    65 	end
       
    66 
       
    67 	oparser.on_tail( '--version', '-V', "Print Ezmlm library version on STDOUT and quit." ) do
       
    68 		$stdout.puts Ezmlm::VERSION
       
    69 		exit!( 0 )
       
    70 	end
       
    71 end
       
    72 
       
    73 
       
    74 # Parse command-line flags and display the help if there isn't exactly one argument
       
    75 remaining_args = oparser.parse( ARGV )
       
    76 if remaining_args.nitems != 1
       
    77 	$stderr.puts( oparser )
       
    78 	exit( 64 ) # EX_USAGE
       
    79 end
       
    80 
       
    81 listsdir = remaining_args.shift
       
    82 daemon = Ezmlm::ListDaemon.new( listsdir, opts )
       
    83 daemon.start.join