#!/bin/bash
###################################################################################
# File.......: /usr/lib/setup/armedslack-hwm-os-configure
# Called from: /usr/lib/setup/SeTconfig
#              This is post package installation, and during the configuration
#              routines.
# Purpose....: Configure Hardware Models from within the Slackware Installer
# Version....: 1.00
# Date.......: 01-Feb-2022
# Author.....: Stuart Winter <mozes@slackware.com>
###################################################################################
#
# Copyright 2022  Stuart Winter, Donostia, Spain.
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# This is the code within /usr/lib/setup/SeTconfig:
# Here, we call each script in /var/log/setup. Two arguments are provided:
# 1 -- the target prefix (normally /, but ${T_PX} from the bootdisk)
# 2 -- the name of the root device.
#( cd $T_PX
#  if [ -x var/log/setup/$SCRIPT ]; then
#  ./var/log/setup/$SCRIPT $T_PX $ROOT_DEVICE
#  fi

# Location of the root file system:
T_PX=$1

# Sanity checks:
[ ! -f /proc/device-tree/model ] && exit 0

# Extract the Hardware Model name:
HWM=$( strings /proc/device-tree/model 2>/dev/null )
[ -z "${HWM}" ] && exit 0

# Collapse all 32bit ARM & x86 variants of 'i?86' into a single
# platform: 'x86' and 'arm' respectively.
ARCH=$( uname -m | sed -e 's%i[0-9]86%x86%g' -e 's?arm.*?arm?g' )

# Location of Hardware Model os-configuration helpers and assets
# within the Slackware Installer:
hwm_osconfigpath=/usr/share/hwm-configure/platform/$ARCH/

# Run any Hardware Model setup scripts found within the Installer for
# this architecture:
[ -d ${hwm_osconfigpath}/helper.scr ] && {
   for platformscr in ${hwm_osconfigpath}/helper.scr/* ; do
      unset hwm # this is used within the scripts for directory names
      . $platformscr
   done ;}
