#!/bin/bash
# Filename:      /etc/grml/fai/config/scripts/GRMLBASE/10-build-initramfs
# Purpose:       configure live-initramfs and build initramfs for booting
# Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
# Bug-Reports:   see http://grml.org/bugs/
# License:       This file is licensed under the GPL v2 or any later version.
################################################################################

set -e

fcopy /usr/share/initramfs-tools/scripts/init-top/grml
fcopy /etc/initramfs-tools/hooks/000-udev-shutup
fcopy /etc/initramfs-tools/conf.d/xz-compress

FILE=$(ls -1 $target/boot/vmlinuz-* 2>/dev/null| sort -r | head -1)
KERNELVERSION=$(echo "${FILE##$target/boot/vmlinuz-}")

if [ -z "$KERNELVERSION" ] ; then
   echo "Error: No kernel found, can not create initramfs. Exiting.">&2
   exit 1
fi

if [ -f $target/usr/share/initramfs-tools/scripts/live ] ; then
   $ROOTCMD update-initramfs -c -t -k $KERNELVERSION
else
   echo "Error: live-initramfs does not seem to be present, can not create initramfs. Exiting.">&2
   exit 1
fi

## END OF FILE #################################################################
# vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=3
