#!/bin/bash

APPS=$BASH_ARRAY_APPLICATIONS
APPS_SHORTCUTS=$BASH_ARRAY_SHORTCUTS_APPLICATIONS

TARGET_DIR=$CQT_INSTALL_DEB_DIR/$PREFIX/

#creating shortcut
DEST_FILE=
DEST_NAME=
SRC_FILE=
function createShortCut {

    echo "create shortCut"
    rm -f $DEST_FILE
    touch $DEST_FILE

    if test -f $DEST_FILE; then
        echo "[Desktop Entry]" >> $DEST_FILE
        echo "Version=$VERSION" >> $DEST_FILE
        echo "Encoding=UTF-8" >> $DEST_FILE
        echo "Name=$DEST_NAME" >> $DEST_FILE
        echo "Type=Application" >> $DEST_FILE
        echo "Icon=$TARGET_DIR/icons/${DEST_NAME}.png" >> $DEST_FILE
        echo "Terminal=false" >> $DEST_FILE
        echo "Exec=$SRC_FILE" >> $DEST_FILE

        chmod 775 $DEST_FILE
    fi
}

echo "Available commands:"

for app in "${APPS[@]}"
do
    
    if [ ! -e /usr/bin/"${app,,}" ]; then
        ln -s "$TARGET_DIR/$app.sh" /usr/bin/"${app,,}"
        echo "${app,,}"
    fi
done

for app in "${APPS_SHORTCUTS[@]}"
do

    DEST_NAME=${app%.*}

    SRC_FILE="$TARGET_DIR/$app"
    DEST_FILE="/usr/share/applications/${DEST_NAME}.desktop"
    createShortCut
done


