#!/bin/sh

if ! [ $(id -u) = 0 ]
then
   echo "This script must be run as root, try:  sudo ./install" 
   exit 1
fi

if [ `uname -m` = "x86_64" ]
then
    echo "x86_64 systen detected, OK."
else
    echo "Sorry, this is no x86_64 sytsem. Installation aborted."
    exit 1
fi


VERSTR=`strings libph330.so | grep "LIBPH330 VERSION"`

if [ -z "$VERSTR" ]
then
    echo "Library version info not found. Installation aborted."
    exit 1
else
    echo installing $VERSTR
fi


mkdir -p /usr/local/lib64/ph330
cp libph330.so /usr/local/lib64/ph330/
chmod 755 /usr/local/lib64/ph330/libph330.so
cp ph330lib.h  /usr/local/lib64/ph330/
cp ph330defin.h  /usr/local/lib64/ph330/
cp errorcodes.h  /usr/local/lib64/ph330/
chmod 644 /usr/local/lib64/ph330/*.h


# The following links are for software that does not find
# the lib at runtime if it is not in the libary search path. 
# Since distributions are not consistent as to where the x64 
# libdir is, we check if /usr/lib64 and /usr/lib exist 
# and then create links there. 

if [ -d "/usr/lib64" ]
then
    ln -f /usr/local/lib64/ph330/libph330.so /usr/lib64/libph330.so
fi

if [ -d "/usr/lib" ]
then
    ln -f /usr/local/lib64/ph330/libph330.so /usr/lib/libph330.so
fi
