# Copyright 2006-2009 by Purdue Research Foundation, West Lafayette, IN 47906.
# All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License, version 2.1 as published by the Free Software Foundation.

INSTDIR=$(DESTDIR)/usr/lib
ETCDIR=$(DESTDIR)/etc
VARLOG=$(DESTDIR)/var/log
VARLIB=$(DESTDIR)/var/lib
OWNER=root
GROUP=root
WEBGROUP=www-data
WEBOWNER=www-data

clean:
	rm -f build-stamp configure-stamp

install:
	install --owner $(OWNER) --group $(GROUP) --mode 0755 -d $(INSTDIR)/mw
	install --owner $(OWNER) --group $(GROUP) --mode 0755 -d $(INSTDIR)/mw/bin
	install --owner $(WEBOWNER) --group $(WEBGROUP) --mode 0770 -d $(ETCDIR)/mw
	install --owner $(WEBOWNER) --group $(WEBGROUP) --mode 0755 -d $(VARLIB)/mw
	install --owner $(WEBOWNER) --group $(WEBGROUP) --mode 0755 -d $(VARLOG)/mw
	install --owner $(WEBOWNER) --group $(WEBGROUP) --mode 0755 -d $(VARLOG)/mw/sessions

	install --owner $(OWNER) --group $(GROUP) --mode 0755 -D maxwell $(INSTDIR)/mw/bin/maxwell
	install --owner $(OWNER) --group $(GROUP) --mode 0644 -D maxwell.conf $(INSTDIR)/mw/maxwell.conf-dist

keys:
	@if [ ! -f /etc/mw/maxwell.key.pub ]; then echo 'y\n' | ssh-keygen -t rsa -f /etc/mw/maxwell.key -N '' -C $(WEB_OWNER)@`hostname` ; fi
	@if [ ! -f /etc/mw/notify.key.pub ]; then echo 'y\n' | ssh-keygen -t rsa -f /etc/mw/notify.key -N '' -C root@`hostname` ; fi
	chown www-data /etc/mw/maxwell.key.pub
	chgrp www-data /etc/mw/maxwell.key.pub
	chown www-data /etc/mw/maxwell.key
	chgrp www-data /etc/mw/maxwell.key
	chmod 0400 /etc/mw/maxwell.key
	chmod 0400 /etc/mw/maxwell.key.pub
	chown www-data /etc/mw/notify.key.pub
	chgrp www-data /etc/mw/notify.key.pub
	chown www-data /etc/mw/notify.key
	chgrp www-data /etc/mw/notify.key
	chmod 0400 /etc/mw/notify.key
	chmod 0400 /etc/mw/notify.key.pub
