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