orgads / rpms / kernel

Forked from rpms/kernel 3 years ago
Clone
ba564c
#!/bin/bash
ba564c
7b44cf
list="$1"
7b44cf
buildroot=${list%/*}
ba564c
ba564c
blacklist()
ba564c
{
ba564c
	cat > "$buildroot/etc/modprobe.d/$1-blacklist.conf" <<-__EOF__
ba564c
	# This kernel module can be automatically loaded by non-root users. To
ba564c
	# enhance system security, the module is blacklisted by default to ensure
ba564c
	# system administrators make the module available for use as needed.
ba564c
	# See https://access.redhat.com/articles/3760101 for more details.
ba564c
	#
ba564c
	# Remove the blacklist by adding a comment # at the start of the line.
ba564c
	blacklist $1
ba564c
__EOF__
ba564c
}
ba564c
ba564c
check_blacklist()
ba564c
{
7b44cf
	if modinfo "$buildroot/$1" | grep -q '^alias:\s\+net-'; then
ba564c
		mod="${1##*/}"
ba564c
		mod="${mod%.ko*}"
ba564c
		echo "$mod has an alias that allows auto-loading. Blacklisting."
ba564c
		blacklist "$mod"
ba564c
	fi
ba564c
}
ba564c
ba564c
foreachp()
ba564c
{
ba564c
	P=$(nproc)
ba564c
	bgcount=0
ba564c
	while read mod; do
ba564c
		$1 "$mod" &
ba564c
ba564c
		bgcount=$((bgcount + 1))
ba564c
		if [ $bgcount -eq $P ]; then
ba564c
			wait -n
ba564c
			bgcount=$((bgcount - 1))
ba564c
		fi
ba564c
	done
ba564c
ba564c
	wait
ba564c
}
ba564c
ba564c
[ -d "$buildroot/etc/modprobe.d/" ] || mkdir -p "$buildroot/etc/modprobe.d/"
7b44cf
7b44cf
if [ -s $list ]; then
7b44cf
	cat $list | foreachp check_blacklist
7b44cf
	if ls $buildroot/etc/modprobe.d/* >& /dev/null ; then
7b44cf
		echo "%defattr(-,root,root)" >> $list
7b44cf
		echo "%config(noreplace) /etc/modprobe.d/*-blacklist.conf" >> $list
7b44cf
	fi
7b44cf
else
7b44cf
	# If modules-extra.list is empty the %files section will throw an
7b44cf
	# error.  Add a dummy entry to workaround the problem.
7b44cf
	echo "%defattr(-,root,root)" >> $list
7b44cf
fi