bin/ezmlm-listd
author Michael Granger <mgranger@laika.com>
Wed, 06 Aug 2008 17:38:56 +0000
changeset 8 308f7dc97753
parent 6 66beb495a861
permissions -rwxr-xr-x
Trying to fix the build again.

#!/usr/bin/env ruby
# 
# A startup script for an instance of Ezmlm::ListDaemon.
# $Id$
# 
# Authors:
# * Michael Granger <mgranger@laika.com>
# * Jeremiah Jordan <jjordan@laika.com>
# 

BEGIN {
	require 'pathname'
	basedir = Pathname.new( __FILE__ ).dirname.parent
	libdir = basedir + 'lib'
	
	$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
}

begin
	require 'rubygems'
	require 'optparse'
	require 'ezmlm/listdaemon'
rescue LoadError
	unless Object.const_defined?( :Gem )
		require 'rubygems'
		retry
	end
	raise
end


progname = Pathname.new( $0 ).basename
opts = Ezmlm::ListDaemon.default_options

oparser = OptionParser.new do |oparser|
	oparser.accept( Pathname ) {|path| Pathname.new(path) }

	oparser.banner = "Usage: #{progname.basename} OPTIONS LISTSDIRECTORY"
	oparser.separator 'Version ' + Ezmlm::VERSION

	oparser.separator ''
	oparser.separator 'Options:'
	oparser.on( '--bind ADDRESS', '-b', String, 
		"Specify the address to bind to. Defaults to '#{opts.bind_addr}'" ) do |bindaddr|
		opts.bind_addr = bindaddr
	end

	oparser.on( '--port PORTNUMBER', '-p', Integer,
		"Specify the port to connect to. Defaults to '#{opts.bind_port}" ) do |portnumber|
		opts.bind_port = portnumber
	end


	oparser.separator ''
	oparser.separator 'Other Options:'
	oparser.on( '--debug', '-d', FalseClass, "Turn on debugging" ) do
		$DEBUG = true
		$stderr.puts "Debugging enabled."
		opts.debugmode = true
	end

	oparser.on_tail( '--help', '-h', FalseClass, "Display help for the given command." ) do
		$stderr.puts( oparser )
		exit!( 0 )
	end

	oparser.on_tail( '--version', '-V', "Print Ezmlm library version on STDOUT and quit." ) do
		$stdout.puts Ezmlm::VERSION
		exit!( 0 )
	end
end


# Parse command-line flags and display the help if there isn't exactly one argument
remaining_args = oparser.parse( ARGV )
if remaining_args.nitems != 1
	$stderr.puts( oparser )
	exit( 64 ) # EX_USAGE
end

listsdir = remaining_args.shift
daemon = Ezmlm::ListDaemon.new( listsdir, opts )
daemon.start.join