#!/bin/sh
#
# Author: Michael Conrad <do5mc at aprs4r.org>
#

if [ -z "$RUBY_BIN" ]; then 

  # default 
  RUBY_BIN=/usr/bin/ruby

  # check ruby1.9 binary
  if [ -x /usr/bin/ruby1.9 ]; then 
    RUBY_BIN=/usr/bin/ruby1.9
  fi

fi

if [ -z "$APRS4R_LIB" ]; then
  APRS4R_LIB=/usr/lib/ruby/vendor_ruby
fi

if [ -z "$APRS4R_LOG" ]; then
  APRS4R_LOG=/var/log/aprs4r
fi

if [ -z "$APRS4R_LOCK" ]; then
  APRS4R_LOCK=/var/lock/aprs4r
fi

# create aprs4r lock file 
touch $APRS4R_LOCK

# create aprs4r log directory
mkdir -p $APRS4R_LOG

# limit virtual memory 
if [ ! -z "$APRS4R_ULIMIT" ]; then 
  ulimit -v $APRS4R_ULIMIT
fi

$RUBY_BIN $APRS4R_LIB/aprs4r.rb $1 >> $APRS4R_LOG/aprs4r-stdout.log 2>> $APRS4R_LOG/aprs4r-stderr.log
