#!/bin/bash

pd=`pwd -P`

jhome="$HOME/jaguarlite"

/bin/mkdir -p $jhome/bin
/bin/mkdir -p $jhome/example
/bin/mkdir -p $jhome/lib
/bin/mkdir -p $jhome/include

/bin/cp -f bin/*  $jhome/bin/
/bin/cp -f lib/*  $jhome/lib/
/bin/cp -f include/*  $jhome/include/
/bin/cp -f example/*  $jhome/example

cd $jhome/lib
/bin/rm -f libcrypto.so libssl.so 2>/dev/null
ln -s libcrypto.so.3 libcrypto.so
ln -s libssl.so.3 libssl.so

/bin/rm -f jaguarlitepython.so 2>/dev/null

    pv1=`python --version 2>&1|awk '{print $2}'|cut -d. -f1`
    pv2=`python --version 2>&1|awk '{print $2}'|cut -d. -f2`
    python_ver="${pv1}.${pv2}"
    if [[ $python_ver = "3.8" ]]; then
        ln -s jaguarlitepython3.8.18.so jaguarlitepython.so
    elif [[ $python_ver = "3.9" ]]; then
        ln -s jaguarlitepython3.9.23.so jaguarlitepython.so
    elif [[ $python_ver = "3.10" ]]; then
        ln -s jaguarlitepython3.10.12.so jaguarlitepython.so
    elif [[ $python_ver = "3.11" ]]; then
        ln -s jaguarlitepython3.11.13.so jaguarlitepython.so
    elif [[ $python_ver = "3.12" ]]; then
        ln -s jaguarlitepython3.12.3.so jaguarlitepython.so
    elif [[ $python_ver = "3.13" ]]; then
        ln -s jaguarlitepython3.13.7.so jaguarlitepython.so
    elif [[ $python_ver = "3.14" ]]; then
        ln -s jaguarlitepython3.14.5.so jaguarlitepython.so
    else
        echo "Your Python version $python_ver is not supported in jaguarlitepython"
    fi


cd $pd

echo "JaguarLite has been installed in $jhome"
echo "The link of jaguarlitepython.so is set up for current Python $python_ver"
echo "If in future or in venv your Python is updated, please update the link of jaguarlitepython.so"
