#!/bin/bash

DIR_WITH_LIBS="$(pwd)/libasa-debian"

# Define name of Linux OS
LINUX_VERSION=$(uname -a)
echo "Linux version: $LINUX_VERSION"
if [[ $LINUX_VERSION == *"astra"* ]]
then
    LINUX_VERSION=astra
else
    LINUX_VERSION=ubuntu
fi
echo "XMLRPC libraries for $LINUX_VERSION will be created"

# Create symlinks to libraries
LIBS=(libxmlrpc.so.3.51 libxmlrpc_client.so.3.51 libxmlrpc_util.so.4.51 libxmlrpc_xmlparse.so.3.51 libxmlrpc_xmltok.so.3.51)
for lib in ${LIBS[@]}
do
    if [ ! -L $DIR_WITH_LIBS/$LINUX_VERSION/${lib: 0: -3} ]
    then
        ln -s $DIR_WITH_LIBS/$LINUX_VERSION/$lib $DIR_WITH_LIBS/$LINUX_VERSION/${lib: 0: -3}
        echo "Symlink for $DIR_WITH_LIBS/$LINUX_VERSION/${lib: 0: -3} was created"
    fi
done

echo $DIR_WITH_LIBS/$LINUX_VERSION > lib_config.conf
sudo cp lib_config.conf /etc/ld.so.conf.d
sudo ldconfig
