# $Id: Makefile,v 1.4 2004/02/21 01:25:02 Tux Exp $
# Makefile for installing user space scripts
# Author: Tux

-include ../../Makefile.common

UNPLUG_MSG="\n\nPlease unplug your modem and press 'Enter'"

all: userscripts

userscripts: clean
	umask 0
	mkdir -p tmp
	cat setvars | sed \
		-e "s|@SBIN_DIR@|$(SBINDIR)|g" \
		-e "s|@EU_DIR@|$(EU_DIR)|g" \
		-e "s|@EU_LANG_DIR@|$(EU_LANG_DIR)|g" \
		-e "s|@EU_SCRIPT_DIR@|$(EU_SCRIPT_DIR)|g" \
		-e "s|@USE_HOTPLUG@|$(USE_HOTPLUG)|g" \
		-e "s|@USE_UPD_USB_USERMAP@|$(USE_UPD_USB_USERMAP)|g" \
		-e "s|@USE_IFUPDOWN@|$(USE_IFUPDOWN)|g" \
		-e "s|@DISTRIB@|$(DISTRIB)|g" \
		-e "s|@DISTVER@|$(DISTVER)|g" \
		-e "s|@SIMPLE@|$(SIMPLE)|g" \
		-e "s|@INIT_DIR@|$(INIT_DIR)|g" \
		-e "s|@PPP_DIR@|$(PPP_DIR)|g" \
		-e "s|@HOTPLUG_SCRIPT_DIR@|$(HOTPLUG_SCRIPT_DIR)|g" \
		-e "s|@HOTPLUG_USERMAP_DIR@|$(HOTPLUG_USERMAP_DIR)|g" \
		-e "s|@HOTPLUG_USERMAP_FILE@|$(HOTPLUG_USERMAP_FILE)|g" \
		-e "s|@NET_SCRIPT_DIR@|$(NET_SCRIPT_DIR)|g" \
		-e "s|@EU_LANG@|$(EU_LANG)|g" \
		-e "s|@PPP_OPTIONS_DIR@|$(PPP_OPTIONS_DIR)|g" \
		> tmp/setvars && \
	sed -e "s|exit 123|. $(EU_SCRIPT_DIR)/setvars|" -e "s| 1 == 1 | 0 == 1 |" fctStopAdsl > tmp/fctStopAdsl && \
	sed "s|exit 123|. $(EU_SCRIPT_DIR)/setvars|g" fctStartAdsl > tmp/fctStartAdsl && \
	sed "s|exit 123|. $(EU_SCRIPT_DIR)/setvars|g" startmire > tmp/startmire && \
	sed "s|exit 123|. $(EU_SCRIPT_DIR)/setvars|g" startadsl > tmp/startadsl && \
	sed "s|exit 123|. $(EU_SCRIPT_DIR)/setvars|g" stopadsl > tmp/stopadsl && \
	sed "s|exit 123|. $(EU_SCRIPT_DIR)/setvars|g" eagleconfig > tmp/eagleconfig && \
	sed "s|exit 123|. $(EU_SCRIPT_DIR)/setvars|g" eaglediag > tmp/eaglediag && \
	sed "s|exit 123|. $(EU_SCRIPT_DIR)/setvars|g" eu_dsp > tmp/eu_dsp && \
	sed "s|exit 123|. $(EU_SCRIPT_DIR)/setvars|g" eu_init > tmp/eu_init && \
	sed "s|exit 123|. $(EU_SCRIPT_DIR)/setvars|g" net_cnx_up > tmp/net_cnx_up && \
	sed "s|exit 123|. $(EU_SCRIPT_DIR)/setvars|g" net_cnx_down > tmp/net_cnx_down && \
	sed "s|exit 123|. $(EU_SCRIPT_DIR)/setvars|g" testconnec > tmp/testconnec
	umask 0022


install:
	if test $(USE_IFUPDOWN) == 1 ; then \
		$(INSTALL) -d $(NET_SCRIPT_DIR) && \
		$(INSTALL) -m 0755 tmp/net_cnx_up $(NET_SCRIPT_DIR) && \
		$(INSTALL) -m 0755 tmp/net_cnx_down $(NET_SCRIPT_DIR) && \
		$(INSTALL) -m 0755 net_cnx_pg $(NET_SCRIPT_DIR) ; \
	fi
	$(INSTALL) -d $(SBINDIR) && \
	$(INSTALL) -d $(EU_LANG_DIR) && \
	$(INSTALL) -d $(EU_SCRIPT_DIR) && \
	$(INSTALL) -m 0755 tmp/setvars $(EU_SCRIPT_DIR) && \
	$(INSTALL) -m 0755 tmp/fctStartAdsl $(SBINDIR) && \
	$(INSTALL) -m 0755 tmp/fctStopAdsl $(SBINDIR) && \
	$(INSTALL) -m 0755 tmp/startmire $(SBINDIR) && \
	$(INSTALL) -m 0755 tmp/startadsl $(SBINDIR) && \
	$(INSTALL) -m 0755 tmp/stopadsl $(SBINDIR) && \
	$(INSTALL) -m 0755 tmp/eaglediag $(SBINDIR) && \
	$(INSTALL) -m 0755 tmp/eagleconfig $(SBINDIR) && \
	$(INSTALL) -m 0755 tmp/eu_dsp $(EU_SCRIPT_DIR) && \
	$(INSTALL) -m 0755 tmp/eu_init $(EU_SCRIPT_DIR) && \
	$(INSTALL) -m 0755 tmp/testconnec $(EU_SCRIPT_DIR) && \
	$(INSTALL) -m 0644 usb.usermap $(EU_SCRIPT_DIR) && \
	$(INSTALL) -m 0644 options $(EU_SCRIPT_DIR) && \
	$(INSTALL) -m 0755 lang/de $(EU_LANG_DIR) && \
	$(INSTALL) -m 0755 lang/en $(EU_LANG_DIR) && \
	$(INSTALL) -m 0755 lang/es $(EU_LANG_DIR) && \
	$(INSTALL) -m 0755 lang/fr $(EU_LANG_DIR) && \
	$(INSTALL) -m 0755 lang/f2 $(EU_LANG_DIR) && \
	$(INSTALL) -m 0755 lang/it $(EU_LANG_DIR) && \
	$(INSTALL) -m 0755 lang/pl $(EU_LANG_DIR) && \
	$(INSTALL) -m 0755 lang/p2 $(EU_LANG_DIR) && \
	touch $(EU_SCRIPT_DIR)/lock

uninstall:
	./fctStopAdsl -sf
	# ask the user for unplugging the modem
	if test $(BUILD_MODULE) == 1 ; then \
		echo -e $(UNPLUG_MSG) && \
		read DUMMY ; \
	fi
	# disable [and remove] autostart service
	if test -e $(INIT_DIR)/eagle-usb ; then \
		chkconfig --del eagle-usb 0>/dev/null 1>/dev/null 2>/dev/null ; \
		update-rc.d -f eagle-usb remove 0>/dev/null 1>/dev/null 2>/dev/null ; \
		rm -f $(INIT_DIR)/eagle-usb ; \
	fi
	if test -e $(INIT_DIR)/internet ; then \
		chkconfig --del internet 0>/dev/null 1>/dev/null 2>/dev/null ; \
	fi
	# remove old eagle-usb files (previous versions)
	./uninstOld $(MODULESDIR) $(KERNELSRC) $(DISTRIB) $(DISTVER) $(BUILD_MODULE) && \
	rm -f $(SBINDIR)/fctStartAdsl && \
	rm -f $(SBINDIR)/fctStopAdsl && \
	rm -f $(SBINDIR)/startmire && \
	rm -f $(SBINDIR)/startadsl && \
	rm -f $(SBINDIR)/stopadsl && \
	rm -f $(SBINDIR)/eagleconfig && \
	rm -f $(SBINDIR)/eaglediag && \
	rm -f $(HOTPLUG_SCRIPT_DIR)/eu_dsp && \
	rm -Rf $(HOTPLUG_USERMAP_DIR)/eagle-usb && \
	rm -Rf $(EU_LANG_DIR)
	rm -Rf $(EU_SCRIPT_DIR)
	if test $(USE_UPD_USB_USERMAP) == 1 ; then \
		update-usb.usermap ; \
	fi
	# uninstOld could have suppressed a module too => always run "depmod"
	depmod -a

clean:
	rm -Rf tmp

distclean:

.PHONY: all userscripts install uninstall clean distclean
