#! /bin/bash

# Settings from /etc/sysconfig/filename are available as environment vars
# with the name 'SYS__FILENAME__KEY' (filename converted to upper case).
#
# Not all files are parsed, current list is:
#   bootloader, language
#

if [ -e /etc/default/grub ] ; then
  . /etc/default/grub
  if [ -z "$GRUB_CMDLINE_LINUX_DEFAULT" ] ; then
    echo "Warning: GRUB_CMDLINE_LINUX_DEFAULT is empty"
  fi
else
  echo "/etc/default/grub missing"
  exit 1
fi

case $(arch) in
  x86_64|i?86)
    image=vmlinuz ;;
  ppc*)
    image=vmlinux ;;
  s390*)
    image=image ;;
  armv*)
    image=zImage ;;
  aarch64|riscv64)
    image=Image ;;
  *)
    echo "Architecture $(arch) not supported."
esac

kernel=$(readlink -f /boot/$image)
initrd=$(readlink -f /boot/initrd)
append="$GRUB_CMDLINE_LINUX_DEFAULT"

echo "kernel=$kernel" >$PBL_RESULT
echo "initrd=$initrd" >>$PBL_RESULT
echo -n "append=${append@Q}" >>$PBL_RESULT

exit 0
