#!/bin/bash

echo -e "#********************************************************************************
#*   _    _             _    ____             _   _                 ____ ____   *
#*  | |-.| |.--.-..---.| |-.|  _ \.--.-..---.| |_| |-..---..---.   | _  |  __|  *
#*  | _ || || _  || __||  < |   _/| _  ||   ||  _|   || -_||  _|   ||_| |__  |  *
#*  |___||_||__._||___||_|_||__|  |__._||_|_||___|_|_||___||_|     |____|____|  *
#*   http://www.blackpanther.hu - kbarcza[]blackpanther.hu * Charles Barcza     *
#**************************************************************(c)2002-2022******
"
. /etc/blackPanther-default-apps.conf

DEBUG=1
dbg()
{
	if [ -n "$DEBUG" ]; then
       	echo
       	$SETCOLOR_FAIL
       	echo -e "DBG >> ${@}"
       	$SETCOLOR_NORMAL
       	sleep 0.2
       	else
       	echo "${@}" >/dev/null
    	fi
}

if [ "x86_64" = "$(uname -m)" ] ;then
    LIB="/usr/lib64"
else
    LIB="/usr/lib"
fi
dbg "Path check.."
if [ "$BP_DEFAULT_APPS" = "yes" ]; then
    if [ ! -n "$(echo "$PATH" | grep "$LIB/blackPanther-default-apps/bin" 2>/dev/null)" ]&&[ -d "$LIB/blackPanther-default-apps" ]; then
        export PATH="$LIB/blackPanther-default-apps/bin:$PATH"
    fi
    if [ ! -n "$(echo "$PATH" | grep "$LIB/blackPanther-default-serverapps/bin" 2>/dev/null)" ]&&[ -d "$LIB/blackPanther-default-serverapps" ]; then
        export PATH="/usr/sbin:$LIB/blackPanther-default-serverapps/bin:$PATH"
    fi
    export PATH="/usr/sbin:$PATH"
dbg "PATH: $PATH"
fi

echo "executing_Xsu \"$*\" == $(basename $0) | $PATH"

if [ -n "$DISPLAY" ] && [ "$(basename $0)" == default-exec_su ];then
    dbg "$DISPLAY - executing_gsu \"$*\""

    if [ -x /usr/bin/sudo ];then
        dbg "$DISPLAY - SUDO \"$*\""
	default-terminal "sudo \"$*\" || true"
    else
        dbg "$DISPLAY - SU \"$*\""
	default-terminal "su - -c \"$@\""
    fi

elif [ -n "$DISPLAY" ] && [ "$(basename $0)" == default-exec_gsu ];then
    dbg "$DISPLAY - executing_gsu \"$*\""
    bubblemsg "DefaultExec:" \"$*\"
    default-terminal "default-su -c  $* || true"
elif [ "$(basename $0)" == default-exec_su ];then
    dbg "$DISPLAY - executing_su \"$*\""
    default-terminal "su -c  $* || true"
elif [ "$(basename $0)" == default-exec_gui ];then
    bubblemsg "DefaultExec:" \"$*\"
    dbg "$DISPLAY - executing_gui \"$*\""
    default-terminal $* || true
else
    dbg "$DISPLAY - executing \"$*\""
    default-terminal $* || true
fi
