#!/bin/sh

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

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_IPW.*\):#\1:" \
				-e "s:^\(CONFIG_IEEE80211.*\):#\1:" \
				${KERN}/build/.config
			sed -i -r -e "s:^(#(un)?def.*CONFIG_IPW.*):/*\1*/:" \
				-e "s:^(#(un)?def.*CONFIG_IEEE80211.*):/*\1*/:" \
				${KERN}/build/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*' -or -name 'ieee80211*' | \
			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*' -or -name 'ieee80211*'`
	if [ -n "${FILES}" ]; then
		echo ${FILES}
		[ -e unload ] && . unload
		ask_remove || return 1
	fi

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

do_check


