Pablo Greco 7b2c62
#!/bin/bash
Pablo Greco 7b2c62
Pablo Greco 7b2c62
buildroot="$1"
Pablo Greco 7b2c62
kernel_base="$2"
Pablo Greco 7b2c62
Pablo Greco 7b2c62
blacklist()
Pablo Greco 7b2c62
{
Pablo Greco 7b2c62
	cat > "$buildroot/etc/modprobe.d/$1-blacklist.conf" <<-__EOF__
Pablo Greco 7b2c62
	# This kernel module can be automatically loaded by non-root users. To
Pablo Greco 7b2c62
	# enhance system security, the module is blacklisted by default to ensure
Pablo Greco 7b2c62
	# system administrators make the module available for use as needed.
Pablo Greco 7b2c62
	# See https://access.redhat.com/articles/3760101 for more details.
Pablo Greco 7b2c62
	#
Pablo Greco 7b2c62
	# Remove the blacklist by adding a comment # at the start of the line.
Pablo Greco 7b2c62
	blacklist $1
Pablo Greco 7b2c62
__EOF__
Pablo Greco 7b2c62
}
Pablo Greco 7b2c62
Pablo Greco 7b2c62
check_blacklist()
Pablo Greco 7b2c62
{
Pablo Greco 7b2c62
	if modinfo "$1" | grep -q '^alias:\s\+net-'; then
Pablo Greco 7b2c62
		mod="${1##*/}"
Pablo Greco 7b2c62
		mod="${mod%.ko*}"
Pablo Greco 7b2c62
		echo "$mod has an alias that allows auto-loading. Blacklisting."
Pablo Greco 7b2c62
		blacklist "$mod"
Pablo Greco 7b2c62
	fi
Pablo Greco 7b2c62
}
Pablo Greco 7b2c62
Pablo Greco 7b2c62
foreachp()
Pablo Greco 7b2c62
{
Pablo Greco 7b2c62
	P=$(nproc)
Pablo Greco 7b2c62
	bgcount=0
Pablo Greco 7b2c62
	while read mod; do
Pablo Greco 7b2c62
		$1 "$mod" &
Pablo Greco 7b2c62
Pablo Greco 7b2c62
		bgcount=$((bgcount + 1))
Pablo Greco 7b2c62
		if [ $bgcount -eq $P ]; then
Pablo Greco 7b2c62
			wait -n
Pablo Greco 7b2c62
			bgcount=$((bgcount - 1))
Pablo Greco 7b2c62
		fi
Pablo Greco 7b2c62
	done
Pablo Greco 7b2c62
Pablo Greco 7b2c62
	wait
Pablo Greco 7b2c62
}
Pablo Greco 7b2c62
Pablo Greco 7b2c62
[ -d "$buildroot/etc/modprobe.d/" ] || mkdir -p "$buildroot/etc/modprobe.d/"
Pablo Greco 7b2c62
find "$buildroot/$kernel_base/extra" -name "*.ko*" | \
Pablo Greco 7b2c62
	foreachp check_blacklist
Pablo Greco 7b2c62
Pablo Greco 7b2c62
# Many BIOS-es export a PNP-id which causes the floppy driver to autoload
Pablo Greco 7b2c62
# even though most modern systems don't have a 3.5" floppy driver anymore
Pablo Greco 7b2c62
# this replaces the old die_floppy_die.patch which removed the PNP-id from
Pablo Greco 7b2c62
# the module
Pablo Greco 7b2c62
if [ -f $buildroot/$kernel_base/extra/drivers/block/floppy.ko* ]; then
Pablo Greco 7b2c62
	blacklist "floppy"
Pablo Greco 7b2c62
fi