#
# 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 2016 Alexander Pyhalov
# Copyright 2022 Andreas Wacknitz
#

%file% barman.conf
%file% barman.conf.4
%file% exec_attr
%file% prof_attr
%file% user_attr

%patch% 01-test-deps.patch
%patch% 02-tests-cloud.patch
%patch% 03-test-disable-failing.patch

%hook-begin%
# https://github.com/EnterpriseDB/barman/issues/866
DOWNLOAD_URL='https://github.com/EnterpriseDB/barman/archive/refs/tags/release/$(HUMAN_VERSION).tar.gz'

%include-2%
COMPONENT_FMRI =		database/postgres/barman
COMPONENT_CLASSIFICATION =	System/Databases

# Github tarball use different source directory than sdist
COMPONENT_SRC =			barman-release-$(HUMAN_VERSION)

# 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%
# Make sure man pages are installed at proper location
PYTHON_DATA=$(USRDIR)

# Install example configuration files
COMPONENT_POST_INSTALL_ACTION += \
	DOC_DIR=$(PROTO_DIR)/usr/share/barman ; \
	$(MKDIR) $$DOC_DIR ; \
	$(CP) $(SOURCE_DIR)/doc/barman.conf $$DOC_DIR/barman.conf-example ; \
	for file in $(SOURCE_DIR)/doc/barman.d/*.conf-template ; do \
		$(CP) $$file $$DOC_DIR/$$(basename $$file | $(GSED) -e 's:template:example:g') ; \
	done ;

# Install additional /etc files
COMPONENT_POST_INSTALL_ACTION += \
	$(INSTALL) -d $(PROTOETCSECDIR)/exec_attr.d ; \
	$(INSTALL) $(COMPONENT_DIR)/files/exec_attr $(PROTOETCSECDIR)/exec_attr.d/barman ; \
	$(INSTALL) -d $(PROTOETCSECDIR)/prof_attr.d ; \
	$(INSTALL) $(COMPONENT_DIR)/files/prof_attr $(PROTOETCSECDIR)/prof_attr.d/barman ; \
	$(INSTALL) -d $(PROTOETCDIR)/user_attr.d/prof_attr.d ; \
	$(INSTALL) $(COMPONENT_DIR)/files/user_attr $(PROTOETCDIR)/user_attr.d/barman ; \
	$(INSTALL) $(COMPONENT_DIR)/files/barman.conf $(PROTOETCDIR)/barman.conf ;

# Install additional man page
COMPONENT_POST_INSTALL_ACTION += \
	$(INSTALL) -d $(PROTOUSRSHAREMAN4DIR) ; \
	$(INSTALL) $(COMPONENT_DIR)/files/barman.conf.4 $(PROTOUSRSHAREMAN4DIR) ;

# We have no packages needed for cloud testing so we need to skip following tests
PYTEST_ADDOPTS += --ignore tests/test_barman_cloud_backup_show.py
PYTEST_ADDOPTS += --ignore tests/test_barman_cloud_wal_archive.py
PYTEST_ADDOPTS += --ignore tests/test_cloud.py
PYTEST_ADDOPTS += --ignore tests/test_cloud_snapshot_interface.py
PYTEST_ADDOPTS += --ignore tests/test_infofile.py
PYTEST_ADDOPTS += --ignore tests/test_output.py

# Random directory name
COMPONENT_TEST_TRANSFORMS += "-e 's|/tmp/.*/garbage[^/]*|\$$(TMPDIR)|'"
%hook-manifest%
cat <<-"EOF" >> "$DISTRIBUTION.p5m"

	# Additional actions
	group groupname=barman gid=91
	user ftpuser=false gcos-field="Barman User" group=barman login-shell=/usr/bin/pfksh password=NP username=barman uid=91 gid=91 home-dir="/var/barman"

	depend fmri=database/postgres-common type=require
	depend fmri=network/rsync type=require

	dir owner=barman group=barman path=var/barman
	dir owner=postgres group=postgres path=var/barman/backup
	dir owner=postgres group=postgres path=var/log/barman
	dir path=etc/barman.d mode=0755

	# Transforms
	<transform file path=etc/barman.conf$ -> default mode 0644>
	<transform file path=etc/barman.conf$ -> default preserve true>
EOF