#############################################################################
# Project:      prj.ABEE.Maintenance
# Started:      2001.09.01 00:00
# Update:       
# Version:
# Author:       Pavel Bekkerman - pavel@abeesoft.org
# Editor:
# Reviewer:
#############################################################################

MAINTENANCE_DIR_ROOT=/usr/local/bin/Maintenance
MAINTENANCE_DIR_LINK=/usr/local/bin/Maintenance-1.4b1
INSTALL_DIR_ROOT=./dist/inst

all:

install:
ifndef MAINTENANCE_DIR_ROOT
	@echo
	@echo "Run configure to set location for the Maintenance package"
	@echo "before you proceed to installation"
	@echo
else

#prepare the repository
	install -d 			$(MAINTENANCE_DIR_LINK)
	rm -f 				$(MAINTENANCE_DIR_ROOT)
	ln -s $(MAINTENANCE_DIR_LINK)	$(MAINTENANCE_DIR_ROOT)

	cp -f dev/Makefile.maintain.defs 	$(MAINTENANCE_DIR_ROOT)
	cp -f dev/Makefile.maintain.rules	$(MAINTENANCE_DIR_ROOT)

# prepare the core
	install -d		$(MAINTENANCE_DIR_ROOT)/core
	cp -fR dev/core/* 	$(MAINTENANCE_DIR_ROOT)/core

# prepare the addons
	install -d		$(MAINTENANCE_DIR_ROOT)/addons
	cp -fR dev/addons/* 	$(MAINTENANCE_DIR_ROOT)/addons

# prepare the etc
	@echo
	@echo "      During UPGRADE from previous version of Maintenance,"
	@echo "      you may be asked if you want to replace your previous"
	@echo "      /etc/Maintenance files."
	@echo

	install	-d			$(MAINTENANCE_DIR_ROOT)/etc
	cp -i dev/conf/config.csh	$(MAINTENANCE_DIR_ROOT)/etc
	cp -i dev/conf/config.sh	$(MAINTENANCE_DIR_ROOT)/etc
	cp -i dev/conf/.maintain	$(MAINTENANCE_DIR_ROOT)/etc

# prepare the /etc/profile.d
	cp -f $(INSTALL_DIR_ROOT)/maintenance.csh	/etc/profile.d/maintenance.csh
	cp -f $(INSTALL_DIR_ROOT)/maintenance.sh	/etc/profile.d/maintenance.sh

# set permissions
	chown -R root	$(MAINTENANCE_DIR_ROOT)
	chgrp -R root	$(MAINTENANCE_DIR_ROOT)
	chmod -R 755	$(MAINTENANCE_DIR_ROOT)

	chown root	/etc/profile.d/maintenance.csh
	chgrp root	/etc/profile.d/maintenance.csh
	chmod 755	/etc/profile.d/maintenance.csh

	chown root	/etc/profile.d/maintenance.sh
	chgrp root	/etc/profile.d/maintenance.sh
	chmod 755	/etc/profile.d/maintenance.sh

# prepare the links
	rm -f 							/etc/Maintenance
	ln -s $(MAINTENANCE_DIR_ROOT)/etc 			/etc/Maintenance

	rm -f 							/usr/bin/maintain
	ln -s $(MAINTENANCE_DIR_ROOT)/core/bin/maintain		/usr/bin/maintain			

	rm -f 							/usr/bin/maintain_ex
	ln -s $(MAINTENANCE_DIR_ROOT)/core/bin/maintain_ex	/usr/bin/maintain_ex			
endif

uninstall:

dist:
	-find . -name CVS -exec rm -fR {} \;
	tar cvf /tmp/abeesoft-maintenance.tar .
	mv /tmp/abeesoft-maintenance.tar .
	gzip abeesoft-maintenance.tar
#	mv abeesoft-maintenance.tar.gz

clean:
	rm -rf *~
	rm -rf $(INSTALL_DIR_ROOT)
	rm -f abeesoft-maintenance.tar.gz
	rm -f Makefile

help:
	@echo "Type: make install"

PHONY_TARGETS	= all clean dist help install uninstall
.PHONY: $(PHONY_TARGETS)
