opi5-efi/post.sh
2023-10-08 13:35:57 +05:30

27 lines
926 B
Bash

#!/usr/bin/env bash
set -xeuf -o pipefail
UNAME_R="$(</boot/.uname)"
BOOT_PART="$(grep '/ ' /etc/fstab | awk '{print $1}')"
cp /opt/opi5-efi/boot.cmd "/boot/efi/boot.cmd"
cp /opt/opi5-efi/uEnv.txt "/boot/efi/uEnv.txt"
if [ ! -f /boot/.uname ]; then
echo "ERROR: No /boot/.uname found to extract 'uname -r' from."
exit 1
fi
if [ ! -f "/boot/initramfs-${UNAME_R}.img" ]; then
echo "Initramfs not found... regenerating."
/sbin/installkernel "${UNAME_R}" "/boot/.vmlinuz-${UNAME_R}-rpm" "/boot/.System.map-${UNAME_R}-rpm"
mv "/boot/vmlinuz-${UNAME_R}.old" "/boot/vmlinuz-${UNAME_R}"
fi
echo "rootdev=${BOOT_PART}" >> "/boot/efi/uEnv.txt"
sed -i "s/setenvrootdev/setenv rootdev \"${BOOT_PART}\"/" "/boot/efi/boot.cmd"
mkimage -A arm -T ramdisk -C none -n uInitrd -d "/boot/initramfs-${UNAME_R}.img" "/boot/uInitrd-${UNAME_R}"
mkimage -C none -A arm -T script -d "/boot/efi/boot.cmd" "/boot/efi/boot.scr"