#!/usr/bin/sh

# lfs-ryco update-initrd script
# last updated 2025-11-20

# silently exit if dracut is not found
if [ -z "$(which dracut)" ]; then
    exit 0
fi

# root required
if [ "$EUID" -ne 0 ]; then
    echo "root required" >&2
    exit 1
fi

# installed with linux-image
MODVER="/usr/lib/modules/.modver"
if [ -z "${MODDIR}" -a -f "${MODVER}" ]; then
    MODDIR=$(cat ${MODVER} 2>/dev/null)
fi

# default initrd
if [ -z "$INITRD" ]; then
    INITRD=/boot/initrd
fi

# moddir required
if [ -z "${MODDIR}" ]; then
    exit 1
fi

dracut --force ${INITRD} ${MODDIR} ${@}
