#!/bin/bash
KDENLIVE_MODEL_DIR=/opt/ai/kdenlive/kdenlive_models

THIS_PATH="$( cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
ACTION="$1"
shift
PACKAGE_LIST=$@

case $ACTION in
    getStatus)
	if [[ " ${PACKAGE_LIST[*]} " == *" kdenlive-models "* ]];then
	    if [ -d "$KDENLIVE_MODEL_DIR" ];then
		echo 0
	    else
		echo 1
	    fi
	elif [[ " ${PACKAGE_LIST[*]} " == *" kdenlive "* ]];then
	    [ "$(dpkg-query -W -f='${Status}' kdenlive 2>/dev/null)" = "install ok installed" ] && echo 0 || echo 1
	elif [[ " ${PACKAGE_LIST[*]} " == *" llx-kdenlive "* ]];then
	    [ "$(dpkg-query -W -f='${Status}' llx-kdenlive 2>/dev/null)" = "install ok installed" ] && echo 0 || echo 1
	else
	    echo "Not Found"
	fi
    ;;
    installPackage)
	if [[ " ${PACKAGE_LIST[*]} " == *" kdenlive-models "* ]];then
            epic -u install ai-models.epi kdenlive-models
	else
	    echo "Not Found"
	fi
    ;;
    download)
    ;;
    remove)
	if [[ " ${PACKAGE_LIST[*]} " == *" kdenlive-models "* ]];then
            epic -u uninstall ai-models.epi kdenlive-models
	elif [[ " ${PACKAGE_LIST[*]} " == *" kdenlive "* ]];then
	    [ "$(dpkg-query -W -f='${Status}' kdenlive 2>/dev/null)" = "install ok installed" ] && apt-get -y remove kdenlive
	elif [[ " ${PACKAGE_LIST[*]} " == *" llx-kdenlive "* ]];then
	    [ "$(dpkg-query -W -f='${Status}' llx-kdenlive 2>/dev/null)" = "install ok installed" ] && apt-get -y remove --purge llx-kdenlive
	else
	    echo "Not Found"
	fi
    ;;	
esac
exit 0
