#
# By Chih-Wei Huang <cwhuang@linux.org.tw>
# Last updated 2017/01/17
#
# License: GNU Public License
# We explicitely grant the right to use the scripts
# with Android-x86 project.
#

# An auto detect function provided by kinneko
auto_detect()
{
	tmp=/tmp/dev2mod
	echo 'dev2mod() { while read dev; do case $dev in' > $tmp
	sort -r /lib/modules/`uname -r`/modules.alias | \
		sed -n 's/^alias  *\([^ ]*\)  *\(.*\)/\1)busybox modprobe \2;;/p' >> $tmp
	echo 'esac; done; }' >> $tmp
	for f in $(grep -Eh "drm_kms|sound.core|hyperv" /lib/modules/`uname -r`/modules.dep | cut -d. -f1); do
		sed -i "/$(basename $f | sed 's/-/_/g')/d" $tmp
	done
	source $tmp
	cat /sys/bus/*/devices/*/uevent | grep MODALIAS | sed 's/^MODALIAS=//' | awk '!seen[$0]++' | dev2mod
	cat /sys/devices/virtual/wmi/*/modalias | dev2mod
}

load_modules()
{
	if [ "$AUTO_LOAD" = "old" ]; then
		auto_detect
	fi

	# 3G modules
	for m in $EXTMOD; do
		busybox modprobe $m
	done
}
