# x11-skell post installation script.
# Stuart Winter <mozes@slackware.com>
# Jan 2022

# Determine the Hardware Model name:
export ARCH=$( slk-hwm-discover -a )
export HWM=$( slk-hwm-discover )

# Exit silently if we don't detect the Hardware Model.
# This avoids warnings/errors.
# We may need to surface these at some point but for the moment it's not
# a concern.
[ -z "${HWM}" ] && exit 0

# Location of the system Xorg config file:
XORGCONF=etc/X11/xorg.conf.d/xorg.conf

# Determine any xorg config file for the Hardware Model we find ourselves
# running upon:
# The Rpi4 no longer requires a config since work on the VC4 driver
# has progressed.
#case "${HWM}" in
#   "Raspberry Pi 4"*)
#      # To accommodate future divergence:
#      #HWM_XORGCONF=bcm2711/xorg.conf.rpi4 ;;
#      HWM_XORGCONF=generic/xorg.conf.fbdev0 ;;
## The Raspberry Pi 3 uses Xorg auto detection and configuration.
## No need to supply an Xorg config.
##   "Raspberry Pi 3"*)
##      #HWM_XORGCONF=bcm2837/xorg.conf.rpi3 ;;
##      HWM_XORGCONF=generic/xorg.conf.fbdev0 ;;
#esac

case "${HWM}" in
   "Raspberry Pi 5"*)
      HWM_XORGCONF=bcm2712/xorg.conf.rpi5 ;;
esac

# Slackware ARM does not ship an xorg.conf by default, so
# if we find one it means that the user installed it, or it was
# installed from this package.
# Either way, for now we'll do nothing since I don't want to modify
# anybody's config.
# In the future we can install this with the '.new' suffix, but the
# user can always pull it from /usr/share/x11-skel/platform.
[ ! -f $XORGCONF ] && {
   [ -f usr/share/x11-skel/platform/$ARCH/$HWM_XORGCONF ] && \
   install -pm644 usr/share/x11-skel/platform/$ARCH/$HWM_XORGCONF $XORGCONF
}
