#!/bin/bash

# if a config exists, source it (load variables values)
if [ -f /etc/initramfs-regen.conf ]; then
	. /etc/initramfs-regen.conf
fi
# typically no $GENERATOR is set in the config,
# but it may be set
GENERATOR="${GENERATOR:-}"
# if GENERATOR is not set, dracut will be used
if [ -z "$GENERATOR" ]; then
	if command -v dracut 2>/dev/null >/dev/null ; then
		# if dracut is installed, run initramfs-regen;
		# if not, assume that it was removed intentionally
		# and do not try to execute it to avoid non-zero exit
		# code of this scripplet and problems with further upgrades
		# (useful for containers without initrd)
		/usr/sbin/initramfs-regen
  fi
else
	# if $GENERATOR was set in the config explicitly,
	# then assume that the user understands what he is doing
	# and try to run initramfs-regen even if
	# dracut is not installed
	/usr/sbin/initramfs-regen
fi 
