#Copyright (c) 2020, 2023 Qualcomm Technologies, Inc.
#All Rights Reserved.
#Confidential and Proprietary - Qualcomm Technologies, Inc.


set -e

QL_MBIM_LICENSE_STORE=/persist/data/pfm/licenses/

echo "Creating MBIM LICENSE STORE : $QL_MBIM_LICENSE_STORE" > /dev/kmsg
mkdir -p ${QL_MBIM_LICENSE_STORE}

if [ -d "${QL_MBIM_LICENSE_STORE}" ]; then

    chmod o+rwx "${QL_MBIM_LICENSE_STORE}"

    files=$(ls /data/mbim/licenses/*.pfm 2> /dev/null | wc -l)
    if [ "$files"  != "0" ]; then
         echo "Source location content" > /dev/kmsg
         ls /data/mbim/licenses/ > /dev/kmsg
         echo "Copying licenses to license store location" > /dev/kmsg
         cp /data/mbim/licenses/*.pfm "${QL_MBIM_LICENSE_STORE}" > /dev/kmsg
         sync
         echo "Copy status is $?" > /dev/kmsg
         chown system:system "${QL_MBIM_LICENSE_STORE}"/*.pfm
         echo "Destination location content" > /dev/kmsg
         ls -l "${QL_MBIM_LICENSE_STORE}" > /dev/kmsg
         echo "Removing Source location files" > /dev/kmsg
         rm -rf /data/mbim/licenses/*.pfm
    fi
 else
    echo "Failed to create License store!!!"  > /dev/kmsg
fi
