#!/sbin/runscript
# Created:20040602
# By Jeff Connelly

# Detect Alps Touchpad on buggy nVidia chipsets
# Gentoo Linux startup script, save as /etc/init.d/alps-detect
# Then do: rc-update add alps-detect default

start() {
	/usr/bin/perl <<'END';
$0 = "alps-detect";
$max = 1;   # max tries

print "$0: detecting touchpad...\n";
$pid = fork;
if ($pid == 0) 
{
    # This process monitors success
    open(DMESG, "tail -n 0 -f /var/log/messages|")||die;
    while(<DMESG>)
    {
        if (m#input: PS/2 Generic Mouse on isa0060/serio4#) {
           print "$0: mouse detected!\n";
           last;
    }
}
system("/etc/init.d/$0 stop");
kill(15, $pid)

} else {
    # Reload and unload modules
    while(1)
    {
        $try++;
        print "$0: removing psmouse ($try)\n";
        system("rmmod psmouse");
        sleep(1);
        print "$0: adding psmouse ($try)\n";
        system("modprobe psmouse");
        sleep(1);
    if ($try>=$max){print"$0: giving up\n";exit;}
    }
}
END
}

