#!/bin/bash

. config

if which firefox > /dev/null || which mozilla > /dev/null; then
    :
else
    echo "Cannot find Firefox or Mozilla"
    echo "CL requires one of these browsers"
    echo "Install Firefox and then run CL installation again"
    echo "Press ENTER to abort installation"
    read a
    exit 1
fi


echo "Installing binaries to $BIN"
mkdir -p "$BIN"
cp -a bin/cl bin/runcl "$BIN"


cd share/fonts

echo "Downloading Mathematica fonts (this may take a while)"
if wget -nv 'http://support.wolfram.com/mathematica/systems/windows/general/files/MathFonts_TrueType_41.exe'; then
    unzip -q MathFonts_TrueType_41.exe
    rm MathFonts_TrueType_41.exe
    echo "Installing Mathematica and TeX fonts to $FONTS"
else
    echo "Could not download Mathematica fonts"
    echo "Installing TeX fonts to $FONTS"
fi

mkdir -p "$FONTS"
cp -a *.ttf "$FONTS"

cd ../..


sed "s'^Exec=~/bin'Exec=${BIN/'/\\'}'" < share/ComeniusUniversity-clausal-language.desktop.template > share/ComeniusUniversity-clausal-language.desktop

echo "Installing icon"
xdg-icon-resource install --size 32 share/ComeniusUniversity-clausal-language.png

echo "Installing menu entry (Aplications/Programming or Applications/Development)"
xdg-desktop-menu install share/ComeniusUniversity-clausal-language.desktop

echo "Installing MIME types"
xdg-mime install share/ComeniusUniversity-clausal-language.xml

echo "Associating CL with the MIME types"
xdg-mime default ComeniusUniversity-clausal-language.desktop text/x-clausal-language
xdg-mime default ComeniusUniversity-clausal-language.desktop application/x-clausal-language
