3c560c6
#!/bin/bash
3c560c6
3c560c6
buildroot="$1"
3c560c6
kernel_base="$2"
3c560c6
3c560c6
blacklist()
3c560c6
{
3c560c6
	cat > "$buildroot/etc/modprobe.d/$1-blacklist.conf" <<-__EOF__
3c560c6
	# This kernel module can be automatically loaded by non-root users. To
3c560c6
	# enhance system security, the module is blacklisted by default to ensure
3c560c6
	# system administrators make the module available for use as needed.
3c560c6
	# See https://access.redhat.com/articles/3760101 for more details.
3c560c6
	#
3c560c6
	# Remove the blacklist by adding a comment # at the start of the line.
3c560c6
	blacklist $1
3c560c6
__EOF__
3c560c6
}
3c560c6
3c560c6
check_blacklist()
3c560c6
{
3c560c6
	if modinfo "$1" | grep -q '^alias:\s\+net-'; then
3c560c6
		mod="${1##*/}"
3c560c6
		mod="${mod%.ko*}"
3c560c6
		echo "$mod has an alias that allows auto-loading. Blacklisting."
3c560c6
		blacklist "$mod"
3c560c6
	fi
3c560c6
}
3c560c6
3c560c6
foreachp()
3c560c6
{
3c560c6
	P=$(nproc)
3c560c6
	bgcount=0
3c560c6
	while read mod; do
3c560c6
		$1 "$mod" &
3c560c6
3c560c6
		bgcount=$((bgcount + 1))
3c560c6
		if [ $bgcount -eq $P ]; then
3c560c6
			wait -n
3c560c6
			bgcount=$((bgcount - 1))
3c560c6
		fi
3c560c6
	done
3c560c6
3c560c6
	wait
3c560c6
}
3c560c6
3c560c6
[ -d "$buildroot/etc/modprobe.d/" ] || mkdir -p "$buildroot/etc/modprobe.d/"
3c560c6
find "$buildroot/$kernel_base/extra" -name "*.ko*" | \
3c560c6
	foreachp check_blacklist