#!/bin/sh

REEDDIR=/usr/local/share/reed-alert/

# check for ecl
type ecl 2>&1 >/dev/null
if [ $? -eq 0 ]
then
	LISP="ecl"
	PARAMS="--norc"
	LOADPARAM="-load"
	SHELLPARAM="-shell"
else
	# check for sbcl if ecl not in PATH
	type sbcl 2>&1 >/dev/null
	if [ $? -eq 0 ]
	then
		LISP="sbcl"
		PARAMS="--noinform --no-userinit"
		LOADPARAM="--script"
		SHELLPARAM="--script"
	else
		echo "ecl or sbcl not found in PATH."
		echo "you need at least one of them to use reed-alert"
		exit 1
	fi
fi

if [ $# -eq 0 ]
then
	echo "usage: $0 filename"
	exit 2
fi

if [ ! -f "$1" ]
then
	echo "$1 not found"
	exit 3
fi

# prevent interpreter output when loading files
$LISP $PARAMS --eval \
"(let ((*standard-output* (make-broadcast-stream)))
   (require 'asdf)
   (load \"$REEDDIR/functions.lisp\")
   (load \"$REEDDIR/probes.lisp\"))" \
   $SHELLPARAM $1
