#!/bin/sh

KERN=/lib/modules/`uname -r`/build

function ask_comment()
{
        while true; do
		read -p "Above definitions found.  Comment out? [y], n "
                case ${REPLY} in
                
		n) return 1;;
                        
		""|y) 	sed -i -e "s:^\(CONFIG_IPW2.*\):#\1:" \
				${KERN}/.config
			sed -i -r -e "s:^(#(un)?def.*CONFIG_IPW2.*):/*\1*/:" \
				${KERN}/include/linux/autoconf.h
			return 1;;
                                
		*) continue;;
                esac
	done
}

function ask_remove()
{
        while true; do
		read -p "Above files found.  Remove? [y],n "
                case ${REPLY} in
                
		n) return 1;;
                        
		""|y) 	find ${KERN} -name 'ipw2*' | \
			while read fn; do 
				[ ! -d ${fn} ] && (rm -f ${fn} || return 1)
			done || return 1
			return 0;;
                                
		*) continue;;
                esac
	done || return 1
}

function do_check()
{
	FILES=$(find ${KERN} -name 'ipw2*')
	if [ -n "${FILES}" ]; then
		echo ${FILES}
		[ -e unload ] && . unload
		ask_remove || return 1
	fi

	( egrep "^(CONFIG_IPW2.*)" ${KERN}/.config || \
		egrep "^#(un)?def.*(CONFIG_IPW2.*)" ${KERN}/include/linux/autoconf.h ) && \
	ask_comment || return 1
}

do_check


