#!/bin/sh

################################################################
#
# Script modified from LINUX/libinstall.sh
# We already installed the prerequisites and do not need to compile SoapySDR.
#
################################################################

################################################################
#
# a) determine the location of THIS script
#    (this is where the files should be located)
#    and assume this is in the pihpsdr directory
#
################################################################

SCRIPTFILE=`realpath $0`
THISDIR=`dirname $SCRIPTFILE`
TARGET=$HOME/pihpsdr
PIHPSDR=$TARGET/release/pihpsdr

echo
echo "=============================================================="
echo "Script file absolute position  is " $SCRIPTFILE
echo "Pihpsdr target       directory is " $TARGET
echo "Icons and Udev rules  copied from " $PIHPSDR
echo "=============================================================="
echo

################################################################
#
# d) create desktop icons, start scripts, etc.  for pihpsdr
#
################################################################

echo "=============================================================="
echo
echo "... creating Desktop Icons"
echo
echo "=============================================================="

rm -f $HOME/Desktop/pihpsdr.desktop
rm -f $HOME/.local/share/applications/pihpsdr.desktop

cat <<EOT > $TARGET/pihpsdr.sh
cd $TARGET
$TARGET/pihpsdr >log 2>&1
EOT
chmod +x $TARGET/pihpsdr.sh

cat <<EOT > $TARGET/pihpsdr.desktop
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Name[eb_GB]=piHPSDR
Exec=$TARGET/pihpsdr.sh
Icon=$TARGET/piHPSDR_logo.png
Name=piHPSDR
EOT

cp $TARGET/pihpsdr.desktop $HOME/Desktop
mkdir -p $HOME/.local/share/applications
cp $TARGET/pihpsdr.desktop $HOME/.local/share/applications

cp $PIHPSDR/piHPSDR_logo.png $TARGET

################################################################
#
# ALL DONE.
#
################################################################

