#!/bin/sh

if ! [ $(id -u) = 0 ]
then
   echo "This script needs root permissions, 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

if ! command -v strings 2>&1 >/dev/null
then 
    echo "error: the strings command was not found"
    echo "try this:  sudo apt-get install binutils" 
    exit 1
fi

VERSTR=`strings libhh500lib.so | grep "HH500LIB VERSION"`

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

INSTDIR=/opt/picoquant/hh500lib
echo to $INSTDIR

mkdir -p $INSTDIR
cp libhh500lib.so $INSTDIR
cp *.h  $INSTDIR
cp *.txt  $INSTDIR
chmod 644 $INSTDIR/*.*

echo $INSTDIR > /etc/ld.so.conf.d/picoquant-hh500lib.conf
ldconfig

# install udev rule for device access permissions
cp HydraHarp500.rules /etc/udev/rules.d

echo "you can verify the installation by running ./chkinst"

