Description:

Long story short. Years ago I adopted dracut for building distroless images. Recently I upgraded dracut to a new version and my automation pipelines started to fail. As it turned out dracut now goes even further and inspects shebang inside scripts and pull corresponding dependencies as it does with regular binaries.

Dracutfile example:

#!/bin/bash

depends() {
    echo "base bash" # <- dracut modules. can contain everything, even your own kubernetes distro.
    return 0
}

install() {
    # postfix user.
    grep '^postfix:' "$dracutsysrootdir"/etc/passwd >> "$initdir/etc/passwd"
    grep '^postfix:' "$dracutsysrootdir"/etc/group >> "$initdir/etc/group"
    grep '^postdrop:' "$dracutsysrootdir"/etc/group >> "$initdir/etc/group"

    # deps.
    inst "/bin/chgrp"
    inst "/bin/egrep"
    inst "/usr/bin/uname"

    mkdir -p "$initdir/var/lib/postfix"
    chown postfix:postfix "$initdir/var/lib/postfix"

    # perl:
    mapfile -t -d '' _filenames < <(equery files --filter=obj,sym dev-lang/perl 2>/dev/null | tr "\n" "\0")
    inst_multiple "${_filenames[@]}"

    # postfix.
    mapfile -t -d '' _filenames < <(equery files --filter=obj,sym mail-mta/postfix 2>/dev/null | grep -v "init.d" | tr "\n" "\0")
    inst_multiple "${_filenames[@]}"

    # ^ I use my own build server (gentoo based) and here I pack everything that belongs to 
    # a specific package (postfix). dracut resolves dependencies and packs it for me into a
    # tar archive, this archive can be easily imported into podman and used as a container.

    # I exclude all package's files which are placed inside "init.d" folder, because 
    # "/etc/init.d/postfix" contains shebang "#!/sbin/openrc-run", and it brings error 
    # on my system, because I don't use OpenRC, but Systemd and this file just is not available.
}