zhang / rpms / kernel

Forked from rpms/kernel 5 years ago
Clone
ba564c
#!/bin/bash
ba564c
4eb337
list="$1"
4eb337
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
{
4eb337
	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/"
4eb337
4eb337
if [ -s $list ]; then
4eb337
	cat $list | foreachp check_blacklist
4eb337
	if ls $buildroot/etc/modprobe.d/* >& /dev/null ; then
4eb337
		echo "%defattr(-,root,root)" >> $list
4eb337
		echo "%config(noreplace) /etc/modprobe.d/*-blacklist.conf" >> $list
4eb337
	fi
4eb337
else
4eb337
	# If modules-extra.list is empty the %files section will throw an
4eb337
	# error.  Add a dummy entry to workaround the problem.
4eb337
	echo "%defattr(-,root,root)" >> $list
4eb337
fi