#!/bin/bash

SHOWUI="/opt/apps/com.ftsafe.interpass3000-cib/files/bin/showUI_CIB_R"

function getUser
{
    user=
    userPath=/run/systemd/users
    userFiles=`ls $userPath` 
    for userFile in $userFiles
    do  
        if [ "${userFile}" -ge "500" ];then
            userState=`awk -F= '{ if($1=="STATE") print $2}' ${userPath}/${userFile}`
            if [ ${userState} == "active" ];then
                user=`awk -F= '{ if($1=="NAME") print $2}' ${userPath}/${userFile}`
                ONLINE_SEATS=`awk -F= '{ if($1=="ONLINE_SEATS") print $2}' ${userPath}/${userFile}`
                SESSIONSID=`awk -F= '{ if($1=="DISPLAY") print $2}' ${userPath}/${userFile}`
                break
            fi  
        fi  
    done

    if [ "$user" == "" ];then
        user=root
    fi  
    echo $user
}
ONLINE_SEATS=
SESSIONSID=

showUser=$(getUser)

userID=`id -u ${showUser}`

EXPORT="export XDG_SESSION_TYPE=x11; "
EXPORT=${EXPORT}"export XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/${showUser}; "
EXPORT=${EXPORT}"export XDG_RUNTIME_DIR=/run/user/${userID}; "
EXPORT=${EXPORT}"export XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0; "
EXPORT=${EXPORT}"export XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0; "
EXPORT=${EXPORT}"export XDG_SESSION_ID=${SESSIONSID}; "
EXPORT=${EXPORT}"export XDG_SEAT=${ONLINE_SEATS}; "


EXPORT=${EXPORT}"export XDG_SESSION_DESKTOP=deepin; " #uos
EXPORT=${EXPORT}"export XDG_CURRENT_DESKTOP=Deepin; " #uos

mate=`ps -ef | grep mate-session | grep -v grep | awk '{printf $2}'`









sudo -i -u $showUser -- bash -c "ls /tmp/ > /dev/null"

if [ $? -ne 0 ]; then 
	${SHOWUI} $1 $2
else
	if [ "$DISPLAY" == "" ];then
		sudo -i -u $showUser -- bash -c "${EXPORT} export DISPLAY=:0; export LANGUAGE=zh_CN; export LANG=zh_CN.UTF-8; ${SHOWUI} $1 $2"
	else
		sudo -i -u $showUser -- bash -c "${EXPORT} ${SHOWUI} $1 $2"
	fi
fi


