#!/bin/bash
### ------------------------------------------------------------------------
# Copyright© Guangzhou r&d center of China telecom co., LTD. 2018-2019. All rights reserved.
# 天翼云电脑客户端启动脚本
# Author: wangyl
### ------------------------------------------------------------------------

BASE_DIR=$(cd `dirname $0`; pwd)

export LD_LIBRARY_PATH=${BASE_DIR}/lib:${LD_LIBRARY_PATH}
export GST_PLUGIN_PATH=${BASE_DIR}/lib/gstreamer-1.0
export GST_PLUGIN_PATH_1_0=${BASE_DIR}/lib/gstreamer-1.0
export PATH=${BASE_DIR}/bin:${PATH}
export CTYUN_EXEC_PATH=${BASE_DIR}/
export GST_VAAPI_ALL_DRIVERS=1
ulimit -n 1024000

if ! $(ps -ef | grep electrond | grep -v grep) && [ -f ${BASE_DIR}/bin/electrond ] ; then
  ${BASE_DIR}/bin/electrond
fi

if ! $(ps -ef | grep ${BASE_DIR}/electron | grep -v grep >/dev/null 2>&1) && [ -f ${BASE_DIR}/bin/CtyunDesktopLaunch ] ; then
  ${BASE_DIR}/bin/CtyunDesktopLaunch --icon-path=${BASE_DIR}/resources/icon_256x256.png --version=v2.5.11 --region=天翼云电脑
fi

#针对PANGU M900设备使用--use-gl=angle
devicename=$(cat /proc/cpuinfo | grep "Hardware" | awk '{print $3}')
devicemodel=$(cat /proc/cpuinfo | grep "Hardware" | awk '{print $4}')
if [ "$devicename" == "PANGU" ] && [ "$devicemodel" == "M900" ] ; then
  ${BASE_DIR}/electron --no-sandbox --use-gl=angle  $@
else
  ${BASE_DIR}/electron --no-sandbox   $@
fi
