###
#
#	(c)opyleft 2007 		by 00ZIE <oozie@poczta.fm> 
#
#   This software gives you no warranty whatsoever, you can copy and modify
#   it under terms and conditions of GPLv2 or later available at 
#
#			http://www.gnu.org/licences/gpl.txt
#
#	This is the executable part of the workaround udev-rule for 
#       	HUAWEI 220 modem on kernels prior to 2.6.20
#		
#    The latest version of this script and many more can be found there:
#		http://oozie.fm.interia.pl/pro/huawei-e220/	
#
#    Version 0x0008
#
####

SYSTEM=$(shell uname -s)
ifeq ("$(SYSTEM)","Linux")
   MAJOR=$(shell uname -r|cut -d\. -f1)
   MINOR=$(shell uname -r|cut -d\. -f2)
   LEVEL=$(shell uname -r|cut -d\. -f3)
endif

info:
	@echo 
	@echo " HUAWEI E220 Linux help   by OOZIE" 
	@echo " ================================= "
	@echo 
	@echo " Usage: "
	@echo
	@echo " make install_suse / make uninstall_suse (to remove)"
	@echo " - tested on openSUSE 10.2, SUSE 10.1"
	@echo 
	@echo " make install_fedora / make uninstall_fedora "
	@echo " - tested on Fedora Core 5 with 2.6.15 kernel"
	@echo
	@echo " make install_ubuntu / make uninstall_ubuntu "
	@echo " - tested on Ubuntu 6.06, Ubuntu 7.04 "
	@echo
	@echo " make install_mandriva / make uninstall_mandriva "
	@echo " - tested on Mandriva Free2007Spring kernel 2.6.17 "
	@echo	
	@echo
	@echo " make config / make remove_config "
	@echo " - this will only copy/remove the configuration files"
	@echo 
	@echo " make generic_install / make generic_uninstall"
	@echo " - If your system is not listed above try the generic option.  "
	@echo " In fact, it's what the other options do more or less :)" 
	@echo 
	@echo "	$(SYSTEM) / kernel $(MAJOR).$(MINOR).$(LEVEL)"
	@echo 

generic_install:
	cp files/99-huawei.rules /etc/udev/rules.d/
	cp files/huawei-mobile.sh /lib/udev/
	udevcontrol reload_rules
	@echo
	@echo " Go ahead and replug your HUAWEI modem."
	@echo

generic_uninstall:
	rm -f /etc/udev/rules.d/99-huawei.rules
	rm -f /lib/udev/huawei-mobile.sh
	@echo
	@echo " -> type make remove_config to loose config files too "
	@echo

install_suse: config generic_install  
uninstall_suse: generic_uninstall
install_fedora: config generic_install  
	@echo " -> FEDORA USER! Double check your /etc/resolv.conf, as in Fedoras"
	@echo "    ip-up does not always work if the device has no ifcfg-* file. "
	@echo
uninstall_fedora: generic_uninstall

install_ubuntu: config generic_install 
	@echo " -> If you are not successful with connecting for the first "
	@echo "    time, simply reboot."

uninstall_ubuntu: generic_uninstall

install_mandriva: generic_install
	@echo 
	@echo " -> After you do this, go to Mandriva Control Centre, Network&Internet,"
	@echo "    Analog Phone, Manual choice -> choose /dev/ttyUSB0, dont choose any "
	@echo "    provider, just proceed with NEXT, evetually type the following: "
	@echo 
	@echo "  Connection name: Your-Provider " 
	@echo "  Phone number   : *99# "
	@echo "  Login ID	: ppp (can be whatever) "
	@echo "  Password	: ppp (can be whatever) "
	@echo "  Authentication : CHAP "
	@echo 
	@echo "    Keep clicking on NEXT and you shall be connected soon ;) "

uninstall_mandriva: 
	
	rm -f /etc/udev/rules.d/99-huawei.rules
	rm -f /lib/udev/huawei-mobile.sh
		
config:
	@echo "Installing sample configuration for $(SYSTEM)"
	@echo 
ifeq ("$(SYSTEM)","Linux")
	cp conf/wvdial-huawei.conf /etc/
	mkdir -p /etc/chatscripts/
	cp conf/huawei-e220.chat /etc/chatscripts/
	cp conf/huawei-e220 /etc/ppp/peers/
endif
remove_config:
	@echo "Removeing configuration for $(SYSTEM)"
	@echo 
ifeq ("$(SYSTEM)","Linux")
	rm -f /etc/wvdial-huawei.conf
	rm -f /etc/ppp/peers/huawei-e220
	rm -f /etc/chatscripts/huawei-e220.chat
endif
default: info
	
