#!/bin/sh
##############################################################################
# If not stated otherwise in this file or this component's LICENSE file the
# following copyright and licenses apply:
#
# Copyright 2020 RDK Management
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##############################################################################

if [ -f /opt/persistent/lsaEnable ]; then
  rm /opt/persistent/lsaEnable
fi

. /etc/include.properties

isLSAEnabled=`tr181 Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.LSA.Enable  2>&1 > /dev/null`

if [ "$isLSAEnabled" = "" ]; then
  isLSAEnabled=`tr181 RFC_ENABLE_LSA  2>&1 > /dev/null`
fi

isLSAEnabled=`echo $isLSAEnabled | tr '[:upper:]' '[:lower:]'`
if [ "$isLSAEnabled" = "true" ]; then
  echo "RBI LSA-M: LSA Enabled" >> $LOG_PATH/ocapri_log.txt

# use following rbiDaemon launch if using rbiDaemon.cfg configuration
#  nohup rbiDaemon -C $PERSISTENT_PATH/rbiDaemon.cfg &> $LOG_PATH/rbiDaemon.log &
# else use following call to use RFC configruation

  prUrl=`tr181 Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.LSA.PlacementReqUrl  2>&1 > /dev/null`
  if [ "$prUrl" = "" ]; then
    prUrl=`tr181 RFC_DATA_LSA_130placementRequestURL  2>&1 > /dev/null`
  fi

  psnUrl=`tr181 Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.LSA.PSNUrl  2>&1 > /dev/null`
  if [ "$psnUrl" = "" ]; then
    psnUrl=`tr181 RFC_DATA_LSA_130placementStatusNotificationURL  2>&1 > /dev/null`
  fi

  nohup rbiDaemon  $prUrl $psnUrl >> $LOG_PATH/rbiDaemon.log &
else
  echo "RBI LSA-M: LSA Disabled" >> $LOG_PATH/ocapri_log.txt
fi
