#!/bin/sh

installDefault="$HOME/Programs/GrimmAudio/ls1-control"
read -p "Install directory [$installDefault]:" installDir
if [ -z "$installDir" ]; then
    installDir="$installDefault"
fi

mkdir -p "$installDir"
cp "ls1-control" "$installDir"
if [ -f *.so ]; then
    cp *.so "$installDir"
fi
cp -r resources "$installDir"

sed "s%\$Path%$installDir%g" "ls1-control-template.desktop" > "ls1-control.desktop"

dataHome="$XDG_DATA_HOME"
if [ -z "$dataHome" ]; then
    dataHome="$HOME/.local/share"
fi
appHome="$dataHome/applications"

which desktop-file-install > /dev/null
if [ $? -eq 0 ]; then
    desktop-file-install --dir="$appHome" "ls1-control.desktop"
    update-desktop-database "$appHome"
else
    mkdir -p "$appHome"
    cp "ls1-control.desktop" "$appHome"/
fi

rm "ls1-control.desktop"

echo "$appHome/ls1-control.desktop" > "$installDir/installed_files.txt"
echo "$dataHome/grimm-audio/ls1-control" >> "$installDir/installed_files.txt"

