#!/bin/bash
# Abstract remove libraries and install new

cd $(dirname $0)


PS3="Which library to install? "
LIBS=$(ls -d x86* | sed -n -e "/^x86$/p" -e "/^x86_64/p" )

select L in $LIBS cancel
do
   case $L in
   cancel )
            echo "cancelled"
            exit 1
            ;;
   * )
            echo "going to install $L"
            break
            ;;
   esac
done

#
# Remove old libraries first
#
sudo rm -f /usr/lib/libmxlin*
sudo rm -f /usr/lib/libmatrix*.so


#
# Copy libraries and make links
#
sudo cp $L/*.a     /usr/lib
sudo cp $L/*.so.*  /usr/lib

if [ -f $L/libmxlin64.so.2.6.0 ]
then
   sudo ln -s /usr/lib/libmxlin64.so.2.6.0 /usr/lib/libmxlin64.so.2.6
   sudo ln -s /usr/lib/libmxlin64.so.2.6   /usr/lib/libmxlin64.so
   sudo ln -s /usr/lib/libmxlin64.so       /usr/lib/libmatrix64.so
else
   sudo ln -s /usr/lib/libmxlin.so.2.6.0 /usr/lib/libmxlin.so.2.6
   sudo ln -s /usr/lib/libmxlin.so.2.6   /usr/lib/libmxlin.so
   sudo ln -s /usr/lib/libmxlin.so       /usr/lib/libmatrix32.so
fi

sudo /sbin/ldconfig 

echo "Following libraries installed:"
ls -l /usr/lib/libmxlin*
ls -l /usr/lib/libmatrix*

