potatogim / rpms / kernel

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