#!/bin/sh

# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2018-present Team LibreELEC (https://libreelec.tv)

if [ "$(cat /sys/firmware/devicetree/base/model)" = "Rockchip RK3328 TRN9" ]; then
  cp -f /usr/lib/kernel-overlays/base/lib/firmware/rtlbt/rtl8723b_config_noflow /var/lib/firmware/rtlbt/rtl8723b_config

  # temporarily disable bluetooth unless bootargs contains bluetooth
  BOOTARGS=$(cat /sys/firmware/devicetree/base/chosen/bootargs) && [ "$BOOTARGS" = "${BOOTARGS/bluetooth/}" ] && exit 1
fi

if [ -d /var/lib/firmware/updates/rtlbt ]; then
  cp -f /var/lib/firmware/updates/rtlbt/* /var/lib/firmware/rtlbt
fi

exit 0
