#!/bin/bash
# If called with $1, it means rpm post-install script giving the argument
# If empty, it will detect last installed kernel to make it the default
kvr="$1"
boot_cfg="/boot/extlinux/extlinux.conf"

# Let's see if we have an arg
if [ -z "$kvr" ] ; then
  export kvr=$(rpm -q --queryformat '%{version}-%{release}' $(rpm -q kernel|tail -n 1))
  echo " Updating ${boot_cfg} to make kernel /vmlinuz-${kvr}.el7.armv7hl the default boot ..."
fi

# Modifiying boot config file

sed -i "s#kernel.*#kernel /vmlinuz-${kvr}.armv7hl#" ${boot_cfg}
sed -i "s#fdtdir.*#fdtdir /dtb-${kvr}.armv7hl#" ${boot_cfg}
sed -i "s#initrd.*#initrd /initramfs-${kvr}.armv7hl.img#" ${boot_cfg}

