# @package      hubzero-forge
# @file         Makefile
# @author       Nicholas J. Kisseberth <nkissebe@purdue.edu>
# @copyright    Copyright (c) 2010-2015 HUBzero Foundation, LLC.
# @license      http://opensource.org/licenses/MIT MIT
#
# Copyright (c) 2012-2015 HUBzero Foundation, LLC.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# HUBzero is a registered trademark of HUBzero Foundation, LLC.
#

USRBIN=$(DESTDIR)/usr/bin
USRSHARE=$(DESTDIR)/usr/share

DIRS=svn svn/trunk svn/trunk/rappture svn/trunk/simtool svn/trunk/src svn/trunk/bin \
     svn/trunk/data svn/trunk/middleware svn/trunk/examples svn/trunk/doc \
     svn/branches svn/tags \
     git git/bin git/data git/doc git/examples \
     git/middleware git/rappture git/simtool git/src \
     templates

KEEPDIRS=git/examples git/rappture git/simtool git/doc git/data git/bin

FILES=getstartGIT.txt.in getstartGITexternal.txt.in getstartSVN.txt.in \
      cover.txt.in images.txt.in link.py.in \
      ldapconf.in image.py.in templates/site_css.cs \
      templates/site_header.cs templates/site_footer.cs templates/site.html

DISTRIBUTION:=$(shell lsb_release -i -s)

all:
	@true

install:
	install --mode 0755 -d $(USRSHARE)/hubzero-forge
	for d in $(DIRS) ; do install --mode 0755 -d $(USRSHARE)/hubzero-forge/$$d ; done
	for f in $(FILES); do install --mode 0644 -D $$f $(USRSHARE)/hubzero-forge/$$f ; done
	install --mode 0755 -D addrepo $(USRBIN)/addrepo 
	install --mode 0755 -D gensvnapache $(USRBIN)/gensvnapache  
	install --mode 0755 -D installtool.exp $(USRBIN)/installtool 
	install --mode 0755 -D finalizetool.exp $(USRBIN)/finalizetool 
	install --mode 0755 -D licensetool.exp $(USRBIN)/licensetool
	install --mode 0644 -D Makefile.tmpl $(USRSHARE)/hubzero-forge/svn/trunk/src/Makefile
	install --mode 0644 -D Makefile.tmpl $(USRSHARE)/hubzero-forge/git/src/Makefile
	install --mode 0755 -D invoke.jupyter.tmpl $(USRSHARE)/hubzero-forge/svn/trunk/middleware/invoke.jupyter
	install --mode 0755 -D invoke.simtool.tmpl $(USRSHARE)/hubzero-forge/svn/trunk/middleware/invoke.simtool
	install --mode 0755 -D invoke.standard.tmpl $(USRSHARE)/hubzero-forge/svn/trunk/middleware/invoke.standard
	install --mode 0644 -D simtoolExample.ipynb.tmpl $(USRSHARE)/hubzero-forge/svn/trunk/simtoolExample.ipynb
	install --mode 0644 -D simtool.ipynb.tmpl $(USRSHARE)/hubzero-forge/svn/trunk/simtool/simtool.ipynb
	install --mode 0755 -D invoke.jupyter.tmpl $(USRSHARE)/hubzero-forge/git/middleware/invoke.jupyter
	install --mode 0755 -D invoke.simtool.tmpl $(USRSHARE)/hubzero-forge/git/middleware/invoke.simtool
	install --mode 0755 -D invoke.standard.tmpl $(USRSHARE)/hubzero-forge/git/middleware/invoke.standard
	install --mode 0644 -D simtoolExample.ipynb.tmpl $(USRSHARE)/hubzero-forge/git/simtoolExample.ipynb
	install --mode 0644 -D simtool.ipynb.tmpl $(USRSHARE)/hubzero-forge/git/simtool/simtool.ipynb
	touch keep; for d in $(KEEPDIRS) ; do install --mode 0644 -D keep $(USRSHARE)/hubzero-forge/$$d/.keep ; done ; rm -f keep
	install --mode 0644 -D README.md.tmpl $(USRSHARE)/hubzero-forge/git/README.md
	install --mode 0755 -D addrepo.sh $(USRBIN)/addrepo.sh
	install --mode 0755 -D addrepoGIT.py $(USRBIN)/addrepoGIT.py
	install --mode 0755 -D addrepoGITexternal.py $(USRBIN)/addrepoGITexternal.py
	install --mode 0755 -D addrepoSVN.py $(USRBIN)/addrepoSVN.py
	install --mode 0755 -D finalizetool.sh $(USRBIN)/finalizetool.sh
	install --mode 0755 -D finalizetoolGIT.py $(USRBIN)/finalizetoolGIT.py
	install --mode 0755 -D finalizetoolGITexternal.py $(USRBIN)/finalizetoolGITexternal.py
	install --mode 0755 -D finalizetoolSVN.py $(USRBIN)/finalizetoolSVN.py
	install --mode 0755 -D gengitExternalapache.py $(USRBIN)/gengitExternalapache.py
	install --mode 0755 -D gengitapache.py $(USRBIN)/gengitapache.py
	install --mode 0755 -D gensvnapache.py $(USRBIN)/gensvnapache.py
	install --mode 0755 -D getExternalGITexternal.py $(USRBIN)/getExternalGITexternal.py
	install --mode 0755 -D git2git.sh $(USRBIN)/git2git.sh
	install --mode 0755 -D git2svn.sh $(USRBIN)/git2svn.sh
	install --mode 0755 -D installtool.sh $(USRBIN)/installtool.sh
	install --mode 0755 -D installtoolGIT.py $(USRBIN)/installtoolGIT.py
	install --mode 0755 -D installtoolGITexternal.py $(USRBIN)/installtoolGITexternal.py
	install --mode 0755 -D installtoolSVN.py $(USRBIN)/installtoolSVN.py

uninstall:
	@true

postinst:
ifeq ($(DISTRIBUTION),Debian)
	adduser --system --home /var/lib/hzsvn --group --quiet --shell /usr/sbin/nologin hzsvn
	adduser --system --home /var/lib/hzgit --group --quiet --shell /usr/sbin/nologin hzgit
else
	adduser --system -m --home-dir /var/lib/hzgit --shell /sbin/nologin hzgit
	adduser --system -m --home-dir /var/lib/hzsvn --shell /sbin/nologin hzsvn
endif

clean:
	@true

.PHONY: all install uninstall postinst clean
