# @package      hubzero-release
# @file         Makefile
# @copyright    Copyright (c) 2018-2020 The Regents of the University of California.
# @license      http://opensource.org/licenses/MIT MIT
#
# Copyright (c) 2018-2020 The Regents of the University of California.
#
# 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 The Regents of the University of California.
#

ETCDIR=$(DESTDIR)/etc
MAJOR_VERSION=`lsb_release -r -s | cut -d . -f 1`

all:
	@true

install:
	if [ -f /etc/debian_version -a $(MAJOR_VERSION) = '6' ]; then install --mode 0644 -D hubzero-julian.list.squeeze $(ETCDIR)/apt/sources.list.d/hubzero-julian.list; fi
	if [ -f /etc/debian_version -a $(MAJOR_VERSION) = '7' ]; then install --mode 0644 -D hubzero-julian.list.wheezy $(ETCDIR)/apt/sources.list.d/hubzero-julian.list; fi
	if [ -f /etc/debian_version -a $(MAJOR_VERSION) = '8' ]; then install --mode 0644 -D hubzero-julian.list.jessie $(ETCDIR)/apt/sources.list.d/hubzero-julian.list; fi
	if [ -f /etc/debian_version -a $(MAJOR_VERSION) = '9' ]; then install --mode 0644 -D hubzero-julian.list.stretch $(ETCDIR)/apt/sources.list.d/hubzero-julian.list; fi
	if [ -f /etc/debian_version ]; then install --mode 0644 -D hubzero-julian.gpg $(ETCDIR)/apt/trusted.gpg.d/hubzero-julian.gpg; fi

	if [ -f /etc/redhat-release -a $(MAJOR_VERSION) = '6' ]; then install --mode 0644 -D hubzero-julian.repo.el6 $(ETCDIR)/yum.repos.d/hubzero-julian.repo; fi
	if [ -f /etc/redhat-release -a $(MAJOR_VERSION) = '7' ]; then install --mode 0644 -D hubzero-julian.repo.el7 $(ETCDIR)/yum.repos.d/hubzero-julian.repo; fi
	if [ -f /etc/redhat-release ]; then install --mode 0644 -D RPM-GPG-KEY-hubzero-julian $(ETCDIR)/pki/rpm-gpg/RPM-GPG-KEY-hubzero-julian; fi

uninstall:
	rm $(ETCDIR)/apt/sources.list.d/hubzero-julian.list
	rm $(ETCDIR)/apt/trustd.gpg.d/hubzero-julian.gpg
	rm $(ETCDIR)/yum.repos.d/hubzero-julian.repo
	rm $(ETCDIR)/pki/rpm-gpg/RPM-GPG-KEY-hubzero-julian

postinst:
	sed -i -e '/packages\.hubzero\.org\/deb/d' /etc/apt/sources.list
	rm -f /etc/yum.repos.d/hubzero-eddie.repo
	if [ -f /etc/debian_version ]; then apt-get update -o APT::List-Cleanup=0 -o Dir::Etc::sourcelist=/etc/apt/sources.list.d/hubzero-julian.list -o Dir::Etc::sourceparts="/dev/null"; fi

clean:
	@true

.PHONY: all install uninstall postinst clean
