#!/bin/bash
#
# This file script invokes CMU CL with the Lisp configuration script, which
# will go into an interactive dialog to determine what systems to load.

echo Welcome to cmuclconfig!

if [ ! -L /usr/lib/cmucl/lisp.core ] ; then
  if [ -f  /usr/lib/cmucl/lisp.core ] ; then
    echo Old version of lisp.core found, removing...
    if [ -f /usr/lib/cmucl/lisp-safe.core -o \
         -f /usr/lib/cmucl/lisp-small.core ] ; then
	 rm -f /usr/lib/cmucl/lisp.core
    else
         echo Hey there is no safe of small core installed.
         echo I fear your installation if fucked-up :-\(
         exit 1
    fi
  fi
  while [ ! -L /usr/lib/cmucl/lisp.core ] ;  do
	cat <<EOF
	
There is now a choice of cores to run: a small one or a
larger safe one: the following are installed, which do 
you want to use as the normal lisp core?

Available cores:
EOF
        a=`find /usr/lib/cmucl/ -name "*.core" -not -name "kernel.core" \
                                -printf "%f\n"`
	  
        echo $a
	echo 
	echo -n "Your choice: "
        read b
	for i in $a ; do 
          if [ $i = $b ] ; then
            echo 
            echo Selecting image $b
            ln -sf /usr/lib/cmucl/$b /usr/lib/cmucl/lisp.core
            echo If you want to reconfigure, just 
	    echo remove /usr/lib/cmucl/lisp.core
          fi
        done
     done
fi
lisp -eval '(load (open "library:config.lisp"))' -noinit
