
CURDIR=`pwd`

A=`whoami`

if [ $A != 'root' ]; then
   echo "You have to be root to run this script"
   exit 1;
fi

file=$( ls h2api/lib/x86_64/libh2api.so.* )
file=$( basename $file )
version=${file#*so.}
majornum=${version%%.*}

cp h2api/configs/h2usb_enum.conf /etc/
cp h2api/configs/h2-cyusb.rules /etc/udev/rules.d/

rm -rf /opt/h2api/
cp -r h2api/ /opt/

#x86_64
ln -sf /opt/h2api/lib/x86_64/libh2api.so.${version} /opt/h2api/lib/x86_64/libh2api.so.${majornum}
ln -sf /opt/h2api/lib/x86_64/libh2api.so.${majornum} /opt/h2api/lib/x86_64/libh2api.so

ln -sf /opt/h2api/lib/x86_64/libusb-1.0.so.0.2.0 /opt/h2api/lib/x86_64/libusb-1.0.so.0
ln -sf /opt/h2api/lib/x86_64/libusb-1.0.so.0 /opt/h2api/lib/x86_64/libusb-1.0.so

#aarch64
ln -sf /opt/h2api/lib/aarch64/libh2api.so.${version} /opt/h2api/lib/aarch64/libh2api.so.${majornum}
ln -sf /opt/h2api/lib/aarch64/libh2api.so.${majornum} /opt/h2api/lib/aarch64/libh2api.so

ln -sf /opt/h2api/lib/aarch64/libusb-1.0.so.0.2.0 /opt/h2api/lib/aarch64/libusb-1.0.so.0
ln -sf /opt/h2api/lib/aarch64/libusb-1.0.so.0 /opt/h2api/lib/aarch64/libusb-1.0.so

#armv7
ln -sf /opt/h2api/lib/armv7/libh2api.so.${version} /opt/h2api/lib/armv7/libh2api.so.${majornum}
ln -sf /opt/h2api/lib/armv7/libh2api.so.${majornum} /opt/h2api/lib/armv7/libh2api.so

ln -sf /opt/h2api/lib/armv7/libusb-1.0.so.0.2.0 /opt/h2api/lib/armv7/libusb-1.0.so.0
ln -sf /opt/h2api/lib/armv7/libusb-1.0.so.0 /opt/h2api/lib/armv7/libusb-1.0.so
