l30013671 / rpms / kernel

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