# Created by Tobias Powalowski <tpowa@archlinux.org>

run_hook ()
{
	if [ -d /lib/modules/$(uname -r)/kernel/drivers/ata/ -a -d /lib/modules/$(uname -r)/kernel/drivers/ide/ ]; then
		msg ":: Echo generate IDE/PATA blacklist..."
		if grep -qw ide-legacy /proc/cmdline; then
			for i in $(echo /lib/modules/$(uname -r)/kernel/drivers/ata/*); do 
				echo "blacklist $(basename $i .ko.gz | grep -e '^pata' -e '^ata_generic' -e '^ata_piix')" >> /etc/modprobe.d/ide-blacklist.conf
			done
			msg "Blacklisted IDE modules (new subsystem) for udev:"
			msg "--------------------------------------"
			if [ -s /etc/modprobe.d/ide-blacklist.conf ]; then 
				for i in $(sort -u /etc/modprobe.d/ide-blacklist.conf | sed -e 's/blacklist //g'); do
					echo -n "$i "
				done
				msg ""
				msg "If you need them, please don't use 'ide-legacy' boot option or load them by hand!"
			else
				msg "No modules blacklisted."
			fi
			msg "--------------------------------------"
		else
			for i in $(echo /lib/modules/$(uname -r)/kernel/drivers/ide/*); do 
				echo "blacklist $(basename $i .ko.gz | grep -v ^ide)" >> /etc/modprobe.d/ide-blacklist.conf
			done
			msg "Blacklisted IDE modules (old subsystem) for udev:"
			msg "--------------------------------------"
			if [ -s /etc/modprobe.d/ide-blacklist.conf ]; then 
				for i in $(sort -u /etc/modprobe.d/ide-blacklist.conf | sed -e 's/blacklist //g'); do
					echo -n "$i "
				done
				msg ""
				msg "If you need them, please use 'ide-legacy' boot option or load them by hand!"
			else
				msg "No modules blacklisted."
			fi
			msg "--------------------------------------"
		fi
	fi
}
