#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright 2024 Geoff Weiss
#

%patch% 01-fix-ipf-path.patch
%patch% 02-use-openindiana-paths.patch
%patch% 03-solaris-readme.patch
%patch% 05-openindiana.log.files.patch
%patch% 06-dont-use-iptables.patch

%file% paths-openindiana.conf

%hook-begin%
# This project is not listed at PyPI so we need to provide all info here.
# See also https://github.com/fail2ban/fail2ban/issues/3917
VERSION='1.1.0'
HOMEPAGE='https://www.fail2ban.org'
DOWNLOAD_URL='https://github.com/fail2ban/fail2ban/archive/refs/tags/$(HUMAN_VERSION).tar.gz'
SUMMARY='Daemon to ban hosts that cause multiple authentication errors'
LICENSE_FILE='COPYING'

%hook-manifest%
# both licenses apply, but license-detector is unable to detect that
sed -i -e 's/^\(COMPONENT_LICENSE =.*\) OR \(.*\)$/\1 AND \2/' Makefile
git add Makefile
# The symlink target is outside the package
printf '<transform link target=/usr/bin/python3\\. -> default pkg.linted.userland.action002.0 true>\n' >> "$MANIFEST"

%include-2%
COMPONENT_CLASSIFICATION=	System/Services
COMPONENT_FMRI =		network/fail2ban

# This is a standalone application.  Since no other Python project depends on
# it we just provide single unversioned package.
SINGLE_PYTHON_VERSION = yes
%include-3%

# Compile Python file(s) at non-default location
COMPONENT_POST_INSTALL_ACTION += $(PYTHON) -mcompileall $(PROTOETCDIR) ;
# Install SMF manifest files.
COMPONENT_POST_INSTALL_ACTION += $(INSTALL) -D $(SOURCE_DIR)/files/solaris-svc-fail2ban $(PROTOLIBDIR)/svc/method/svc-fail2ban ;
COMPONENT_POST_INSTALL_ACTION += $(INSTALL) -D $(SOURCE_DIR)/files/solaris-fail2ban.xml $(PROTOLIBDIR)/svc/manifest/network/solaris-fail2ban.xml ;
# Remove paths files for other OS's.
COMPONENT_POST_INSTALL_ACTION += $(RM) $(PROTOETCDIR)/fail2ban/paths-arch.conf ;
COMPONENT_POST_INSTALL_ACTION += $(RM) $(PROTOETCDIR)/fail2ban/paths-debian.conf ;
COMPONENT_POST_INSTALL_ACTION += $(RM) $(PROTOETCDIR)/fail2ban/paths-fedora.conf ;
COMPONENT_POST_INSTALL_ACTION += $(RM) $(PROTOETCDIR)/fail2ban/paths-freebsd.conf ;
COMPONENT_POST_INSTALL_ACTION += $(RM) $(PROTOETCDIR)/fail2ban/paths-opensuse.conf ;
COMPONENT_POST_INSTALL_ACTION += $(RM) $(PROTOETCDIR)/fail2ban/paths-osx.conf ;
# Add openindiana paths file.
COMPONENT_POST_INSTALL_ACTION += $(INSTALL) -D $(COMPONENT_DIR)/files/paths-openindiana.conf $(PROTO_DIR)/etc/fail2ban/paths-openindiana.conf ;