### Slackware Installer script ############################################################
# Script......: /usr/share/hwm-configure/platform/aarch64/installer/helper.scr/rpi-os-setup
# Called from : /usr/lib/setup/armedslack-postinstall-scripts/001-hwm-os-configure
# Purpose.....: Operating System configuration helper for Hardware Models:
#               * Raspberry Pi
# Author......: Stuart Winter <mozes@slackware.com>
# Date........: 19-Oct-2025
### Changelog ######################################################
# 09-Apr-2022: Initial version
# 19-Oct-2025: Validate that the extlinux config exists before editing.
#              This file won't exist for the Raspberry Pi's since migrating to its
#              native BL.
### Slackware Installer script ############################################################

# The newly installed OS' /etc/fstab:
fstabfile=${T_PX}/etc/fstab

# U-Boot Boot Loader configuration file - no longer used, but remains here
# for reference and should we ever need to return (unlikely!)
bootloaderconf=${T_PX}/boot/extlinux/extlinux.conf

# Hardware Model settings:
case "$HWM" in
#   "Raspberry Pi 4"*)
   "Raspberry Pi"*)
      # The Raspberry Pi's Native Boot Loader will handle loading
      # the Device Tree Blobs, as it's the path of least resistance when encountering
      # variations within the batches of RPi's. The Native Boot Loader takes care of
      # the differences, so we'll prevent U-Boot from handling the DTBs:
      # This setting is also changed in the RPi's handler for the /platform 'inst_dskimg.build'
      # script to ensure that the Slackware Installer has the correct configuration.
      [ -f ${bootloaderconf} ] && sed -i '\?FDTDIR /dtb/?d' ${bootloaderconf}

      # Install a modprobe configuration for the RPi4:
      [ -d ${T_PX}/etc/modprobe.d ] && {
         #[ -f ${hwm_osconfigpath}/assets/rpi/${hwm}/modprobe-rpi.conf ] && {
         [ -f ${hwm_osconfigpath}/assets/rpi/modprobe-rpi.conf ] && {
            install -pm644 ${hwm_osconfigpath}/assets/rpi/modprobe-rpi.conf ${T_PX}/etc/modprobe.d/ ;} ;}
   ;;
esac
