#!/bin/sh -eu
cd $(dirname "$0")

mkdir -p ~/smartecg
drvdir=~/smartecg

echo "Copying files..."
rm -rf $drvdir/jre
cp -r jre $drvdir/jre
cp smartecg.jar ecg-driver-installer.jar smartecg.png smartecg.desktop run.sh $drvdir
sed -i "s/user/$USER/g" $drvdir/smartecg.desktop
install $drvdir/smartecg.desktop ~/.local/share/applications/smartecg.desktop
mkdir -p ~/.config/autostart
install $drvdir/smartecg.desktop ~/.config/autostart/smartecg.desktop

echo "Installing certificate..."
sudo ./setup_root.sh

echo "Reboot to finish installation"