# Avoid problem with official Oracle RPMS not listing necessary capabilities
%global __requires_exclude ^libocci.so|^libclntsh.so

# Generic macros
#---------------
%define name cta
%define ctaVersion @CTA_VERSION@
%define ctaRelease @CTA_RELEASE@

%define usingObjectstore @RPM_USINGOBJECTSTORE@
%define schedOpt @RPM_SCHEDOPT@
%define oracleOpt @RPM_ORACLE@

# Neutral packaging (for srpm)
#-----------------------------
%if 0%{?neutralpackage:1} > 0
%define mydist %{nil}
%else
%define mydist %{?dist}
%endif

# Skipping unit tests (for developers)
#-------------------------------------
%define skip_unit_tests @SKIP_UNIT_TESTS@

# Utility for reloading systemctl when needed
#--------------------------------------------
%define systemdDaemonReload() if [ -e /usr/bin/systemctl ] ; then /usr/bin/systemctl daemon-reload; fi
%define systemdTryRestart() if [ -e /usr/bin/systemctl ] ; then /usr/bin/systemctl try-restart %1; fi

# General settings
#-----------------
Summary: CERN Tape Archive
Name: %{name}
Version: %{ctaVersion}
Release: %{ctaRelease}%{mydist}
Source: %{name}-%{ctaVersion}-%{ctaRelease}.tar.gz
License: GPLv3+
Group: Application/cta

BuildRoot: %{_builddir}/%{name}-%{version}-root
BuildRequires: cmake3 >= 3.17 redhat-rpm-config


# The CTA client is the only component of CTA that can be compiled on both SLC6
# and C77, therefore only the packages it depends on are required for SLC6

%define xrootdVersion 1:4.12.8-1
%if "%{ctaVersion}" == "5"
%define xrootdVersion 1:5.6.1-1
%endif

%define radosVersion 2:15.2.15
BuildRequires: xrootd-client-devel  >= %{xrootdVersion}
BuildRequires: xrootd-devel         >= %{xrootdVersion}
BuildRequires: xrootd-server-devel  >= %{xrootdVersion}
BuildRequires: xrootd-private-devel >= %{xrootdVersion}
BuildRequires: librados-devel = %{radosVersion}, libradosstriper-devel = %{radosVersion},
BuildRequires: protobuf3-compiler >= 3.3.1 protobuf3-devel >= 3.3.1
BuildRequires: gtest-devel >= 1.12.0
BuildRequires: sqlite-devel >= 3.6
BuildRequires: libcap-devel >= 2.16
BuildRequires: binutils-devel >= 2.20
BuildRequires: cryptopp-devel >= 5.6.2
BuildRequires: libuuid-devel >= 2.17
BuildRequires: json-c-devel >= 0.11
BuildRequires: libattr-devel >= 2.4.44
BuildRequires: oracle-instantclient19.3-devel
BuildRequires: postgresql-devel
BuildRequires: valgrind
BuildRequires: valgrind-devel
BuildRequires: grpc, grpc-devel, grpc-static, grpc-plugins
%{?systemd_requires}
BuildRequires: systemd
# only build debug info if you're building the whole code

%description
The CTA project is the CERN Tape Archive system.

%prep
%setup -D -q -n %{name}-%{ctaVersion}-%{ctaRelease}

%build

mkdir -p build
cd build
# The cmake step does the selection between client/server compilation or just client
CTA_VERSION=%{ctaVersion} cmake3 .. -DCOMPILE_PACKAGING:STRING=0 -DVCS_VERSION=%{ctaRelease} %{schedOpt} %{oracleOpt}
# Workaround for the inability of cmake to handle properly the dependencies to generated code.
%{__make} -s %{_smp_mflags} -k || true
%{__make} -s %{_smp_mflags}

%install
%{__rm} -rf ${RPM_BUILD_ROOT}

cd build
%{__make} install DESTDIR=${RPM_BUILD_ROOT} EXPORTMAN=${RPM_BUILD_ROOT}/usr/share/man

%clean
%{__rm} -rf $RPM_BUILD_ROOT
%{__rm} -rf $RPM_BUILD_DIR/%{name}-%{version}


%check
# The CTA client is the only component of CTA that can be compiled on both SLC6
# and C77, therefore thereis no unittest for it
%if "%{?dist}" == ".slc6" || "%{?dist}" == ".el6"
%define skip_unit_tests 1
%endif

%if "%{skip_unit_tests}" == "0"
cd build
%{__make} shortunittests
%endif

# The main packages will be cta-taped, cta-frontend, cta-cli

%package -n cta-taped
Summary: CERN Tape Archive: tape daemon
Group: Application/CTA
Requires: logrotate
Requires: cta-common = %{version}-%{release}
Requires: cta-lib = %{version}-%{release}
Requires: cta-lib-catalogue = %{version}-%{release}
Requires: eos-client
Requires: xrootd-client-libs >= %{xrootdVersion}
%description -n cta-taped
CERN Tape Archive:
The tape server daemon
%files -n cta-taped
%defattr(-,root,root)
%attr(0644,root,root) %config(noreplace) /etc/logrotate.d/cta-taped
%attr(0755,root,root) %{_bindir}/cta-taped
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/cta/cta-taped.conf.example
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/cta/TPCONFIG.example
%attr(0644,root,root) %doc /usr/share/man/man1/cta-taped.1cta.gz
%attr(0644,root,root) %config(noreplace) /etc/sysconfig/cta-taped
%attr(0644,root,root) %config(noreplace) /etc/systemd/system/cta-taped.service

%post -n cta-taped
%systemd_post cta-taped.service
%systemdDaemonReload
%systemdTryRestart cta-taped.service

%preun -n cta-taped
%systemd_preun cta-taped.service

%postun -n cta-taped
%systemd_postun cta-taped.service
%systemdDaemonReload

%package -n cta-frontend
Summary: CERN Tape Archive: Xrootd plugin
Group: Application/CTA
Requires: logrotate
Requires: cta-common = %{version}-%{release}
Requires: cta-lib = %{version}-%{release}
Requires: cta-lib-catalogue = %{version}-%{release}
Requires: xrootd-client-libs >= %{xrootdVersion}
Requires: xrootd-server >= %{xrootdVersion}
%description -n cta-frontend
CERN Tape Archive:
The xroot plugin
%files -n cta-frontend
%defattr(0755,root,root)
%{_libdir}/libXrdSsiCta.so*
%attr(0644,root,root) %config(noreplace) /etc/logrotate.d/cta-frontend
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/cta/cta-frontend-xrootd.conf.example
%attr(0644,root,root) %config(noreplace) /etc/sysconfig/cta-frontend
%attr(0644,cta,tape) /etc/systemd/system/cta-frontend.service

#Frontend installs libraries so we need ldconfig.
%post -n cta-frontend
/sbin/ldconfig
%systemd_post cta-frontend.service
%systemdDaemonReload
%systemdTryRestart cta-frontend.service

%preun -n cta-frontend
%systemd_preun cta-frontend.service

%postun -n cta-frontend
/sbin/ldconfig
%systemd_post cta-frontend.service
%systemdDaemonReload

%posttrans -n cta-frontend
MISSING_CONF=%{_sysconfdir}/cta/cta-frontend-xrootd.conf
if [[ ! -f "${MISSING_CONF}" ]] && [[ -f "${MISSING_CONF}.rpmsave" ]]
then
  mv ${MISSING_CONF}.rpmsave ${MISSING_CONF}
fi

%package -n cta-frontend-grpc
Summary: CERN Tape Archive: gRPC based frontend
Group: Application/CTA
Requires: logrotate
Requires: cta-common = %{version}-%{release}
Requires: cta-lib = %{version}-%{release}
Requires: cta-lib-catalogue = %{version}-%{release}
%description -n cta-frontend-grpc
CERN Tape Archive:
dCache frontend
%files -n cta-frontend-grpc
%defattr(0755,root,root)
%attr(0755,root,root) %{_bindir}/cta-frontend-grpc
%attr(0644,root,root) /etc/systemd/system/cta-frontend-grpc.service
%attr(0644,root,root) /etc/sysconfig/cta-frontend-grpc
%attr(0644,root,root) %doc /usr/share/man/man1/cta-frontend-grpc.1cta.gz

%post -n cta-frontend-grpc
%systemd_post cta-frontend-grpc.service
%systemdDaemonReload
%systemdTryRestart cta-frontend-grpc.service

%preun -n cta-frontend-grpc
%systemd_preun cta-frontend-grpc.service

%postun -n cta-frontend-grpc
%systemd_postun cta-frontend-grpc.service
%systemdDaemonReload

%package -n cta-cli
Summary: CERN Tape Archive: command line interface
Group: Application/CTA
Requires: cta-lib-common = %{version}-%{release}
Requires: xrootd-client-libs >= %{xrootdVersion}
%description -n cta-cli
CERN Tape Archive:
The command line utilities
%files -n cta-cli
%defattr(-,root,root)
%attr(0755,root,root) %{_bindir}/cta-admin
%attr(0644,root,root) %doc /usr/share/man/man1/cta-admin.1cta.gz
%attr(0755,root,root) %{_bindir}/cta-restore-deleted-files
%attr(0644,root,root) %doc /usr/share/man/man1/cta-restore-deleted-files.1cta.gz
%attr(0755,root,root) %{_bindir}/cta-send-event
%attr(0755,root,root) %{_bindir}/cta-send-closew.sh
%attr(0755,root,root) %{_bindir}/cta-verify-file
%attr(0755,root,root) %{_bindir}/cta-change-storage-class-in-catalogue
%attr(0755,root,root) %{_bindir}/cta-eos-namespace-inject
%attr(0644,root,root) %doc /usr/share/man/man1/cta-change-storage-class-in-catalogue.1cta.gz
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/cta/cta-cli.conf.example

%posttrans -n cta-cli
MISSING_CONF=%{_sysconfdir}/cta/cta-cli.conf
if [[ ! -f "${MISSING_CONF}" ]] && [[ -f "${MISSING_CONF}.rpmsave" ]]
then
  mv ${MISSING_CONF}.rpmsave ${MISSING_CONF}
fi

%package -n cta-lib-common
Summary: CERN Tape Archive libraries
Group: Application/CTA
# Explicity require protobuf3 to avoid clash with eos-protobuf3
Requires: protobuf3
Requires: xrootd-client-libs >= %{xrootdVersion}
%description -n cta-lib-common
CERN Tape Archive:
The shared libraries base
%files -n cta-lib-common
%defattr(0755,root,root,-)
%{_libdir}/libctacommon.so*

%package -n cta-lib-catalogue
Summary: CERN Tape Archive libraries
Group: Application/CTA
# Explicity require protobuf3 to avoid clash with eos-protobuf3
Requires: cta-lib-common
Requires: oracle-instantclient19.3-basic
Requires: postgresql-libs
Requires: xrootd-client-libs >= %{xrootdVersion}
%description -n cta-lib-catalogue
CERN Tape Archive:
Shared libraries required to access the CTA catalogue
%files -n cta-lib-catalogue
%defattr(0755,root,root,-)
%{_libdir}/libctacatalogue.so*
%{_libdir}/libctadropschemacmd.so*
%{_libdir}/libctardbms.so*
%{_libdir}/libctardbmswrapper.so*
%{_libdir}/libctaschemachecker.so*
%{_libdir}/libctastatistics.so*

%package -n cta-lib
Summary: CERN Tape Archive libraries
Group: Application/CTA
Requires: librados2 = %{radosVersion}
%if "%{usingObjectstore}" == "0"
Requires: postgresql-libs
%endif
Requires: xrootd-client-libs >= %{xrootdVersion}
# Explicity require protobuf3 to avoid clash with eos-protobuf3
Requires: protobuf3
Requires: cta-lib-common = %{version}-%{release}
%description -n cta-lib
CERN Tape Archive:
The shared libraries
%files -n cta-lib
%defattr(0755,root,root,-)
#TODO: merge util and common
%{_libdir}/libctascheduler.so*
%if "%{usingObjectstore}" != "0"
%{_libdir}/libctaobjectstore.so*
%endif
%{_libdir}/libctamediachanger.so*
%{_libdir}/libctamessages.so*
%{_libdir}/libctamessagesutils.so*
%{_libdir}/libctarao.so*
%{_libdir}/libctadisk.so*
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/cta/cta-catalogue.conf.example

#CTA-lib installs libraries so we need ldconfig.
%post -n cta-lib -p /sbin/ldconfig
%postun -n cta-lib -p /sbin/ldconfig

%package -n cta-systemtests
Summary: CERN Tape Archive: unit and system tests with virtual tape drives
Group: Application/CTA
Requires: valgrind >= 3.8.1
Requires: cta-lib = %{version}-%{release}
Requires: cta-taped = %{ctaVersion}-%{ctaRelease}%{mydist}
Requires: make
Requires: moreutils
Requires: xrootd-client-libs >= %{xrootdVersion}
Requires: gtest-devel >= 1.12.0
%description -n cta-systemtests
CERN Tape Archive:
Unit tests and system tests with virtual tape drives
%files -n cta-systemtests
%defattr(0755,root,root,-)
%{_libdir}/libsystemTestHelperTests.so*
%{_libdir}/libcta-tapedSystemTests.so*
%{_bindir}/cta-rdbmsUnitTests
%{_bindir}/cta-rdbmsUnitTests-oracle.sh
%{_bindir}/cta-unitTests
%{_bindir}/cta-unitTests-multiProcess
%{_bindir}/cta-valgrindUnitTests.sh
%{_bindir}/cta-unitPlusSystemTests.sh
%{_bindir}/cta-osmReaderTest
%{_libdir}/libctacataloguecmdlineunittests.so*
%{_libdir}/libctacommonunittests.so*
%{_libdir}/libctafrontendcommonconfigunittests.so*
%{_libdir}/libctadbconfigcatalogueunittests.so*
%{_libdir}/libctadbconfigconnunittests.so*
%{_libdir}/libctadbconfigstmtunittests.so*
%{_libdir}/libctaexceptionunittests.so*
%{_libdir}/libctainmemorycatalogueunittests.so*
%{_libdir}/libctainmemoryconnunittests.so*
%{_libdir}/libctainmemorystmtunittests.so*
%if "%{usingObjectstore}" != "0"
%{_libdir}/libctaobjectstoreunittests.so*
%endif
%{_libdir}/libctardbmsunittests.so*
%{_libdir}/libctardbmswrapperunittests.so*
%{_libdir}/libctaschedulerunittests.so*
%{_libdir}/libctatapeserverdaemonunittests.so*
%{_libdir}/libctatapeserverdriveunittests.so*
%{_libdir}/libctatapeserverfileunittests.so*
%{_libdir}/libctatapeserverscsiunittests.so*
%{_libdir}/libctadaemonunittests.so*
%{_libdir}/libctamediachangerunittests.so*
%{_libdir}/libctadiskunittests.so*
%{_libdir}/libctatapelabelunittests.so*
%{_libdir}/libctatapeserverraounittests.so*
%{_bindir}/cta-systemTests
%{_libdir}/libctadaemonunittests-multiprocess.so*
%attr(0644,root,root) %{_datadir}/%{name}-%{ctaVersion}/unittest/*.suppr
%attr(0644,root,root) %{_datadir}/%{name}-%{ctaVersion}/unittest/parallelTestsMakefile

%package -n cta-immutable-file-test
Summary: CERN Tape Archive: command-line tool for testing immutable files
Group: Application/CTA
Requires: cta-lib-common = %{version}-%{release}
Requires: xrootd-client-libs >= %{xrootdVersion}
%description -n cta-immutable-file-test
CERN Tape Archive:
Command-line tool for testing immutable files
%files -n cta-immutable-file-test
%defattr(0755,root,root,-)
%{_bindir}/cta-immutable-file-test

%if "%{usingObjectstore}" != "0"
%package -n cta-objectstore-tools
Summary: CERN Tape Archive: object store tools
Group: Application/CTA
Requires: cta-lib = %{version}-%{release}
Requires: xrootd-client-libs >= %{xrootdVersion}
%description -n cta-objectstore-tools
CERN Tape Archive:
Tools allowing initialization and inspection of the object store.
%files -n cta-objectstore-tools
%attr(0755,root,root) %{_bindir}/cta-objectstore-initialize
%attr(0755,root,root) %{_bindir}/cta-objectstore-list
%attr(0755,root,root) %{_bindir}/cta-objectstore-dump-object
%attr(0755,root,root) %{_bindir}/cta-objectstore-dereference-removed-queues
%attr(0755,root,root) %{_bindir}/cta-objectstore-collect-orphaned-object
%attr(0755,root,root) %{_bindir}/cta-objectstore-create-missing-repack-index
%endif

#cta-systemtests installs libraries so we need ldconfig.
%post -n cta-systemtests -p /sbin/ldconfig
%postun -n cta-systemtests -p /sbin/ldconfig

%package -n cta-catalogueutils
Summary: Utilities to faciliate working with the CTA catalogue
Group: Application/CTA
Requires: cta-lib-catalogue = %{version}-%{release}
Requires: xrootd-client-libs >= %{xrootdVersion}
%description -n cta-catalogueutils
CERN Tape Archive:
Scripts and utilities to faciliate working with the CTA catalogue
%files -n cta-catalogueutils
%attr(0755,root,root) %{_bindir}/cta-catalogue-admin-user-create
%attr(0755,root,root) %{_bindir}/cta-catalogue-schema-create
%attr(0755,root,root) %{_bindir}/cta-catalogue-schema-drop
%attr(0755,root,root) %{_bindir}/cta-catalogue-schema-set-production
%attr(0755,root,root) %{_bindir}/cta-catalogue-schema-verify
%attr(0755,root,root) %{_bindir}/cta-database-poll
%attr(0755,root,root) %{_bindir}/cta-statistics-save
%attr(0755,root,root) %{_bindir}/cta-statistics-update
%attr(0644,root,root) %doc /usr/share/man/man1/cta-catalogue-admin-user-create.1cta.gz
%attr(0644,root,root) %doc /usr/share/man/man1/cta-catalogue-schema-create.1cta.gz
%attr(0644,root,root) %doc /usr/share/man/man1/cta-catalogue-schema-drop.1cta.gz
%attr(0644,root,root) %doc /usr/share/man/man1/cta-catalogue-schema-set-production.1cta.gz
%attr(0644,root,root) %doc /usr/share/man/man1/cta-catalogue-schema-verify.1cta.gz
%attr(0644,root,root) %doc /usr/share/man/man1/cta-database-poll.1cta.gz

%if "%{usingObjectstore}" == "0"
%package -n cta-scheduler-utils
Summary: Utilities to faciliate working with the CTA scheduler database
Group: Application/CTA
Requires: postgresql-libs
%description -n cta-scheduler-utils
CERN Tape Archive:
Scripts and utilities to faciliate working with the CTA scheduler database
%files -n cta-scheduler-utils
%attr(0755,root,root) %{_bindir}/cta-scheduler-schema-create
%attr(0755,root,root) %{_bindir}/cta-scheduler-schema-drop
%endif

%package -n cta-rmcd
Summary: The Remote Media Changer daemon (rmcd)
Group: Application/CTA
Requires: logrotate
Requires: cta-common = %{version}-%{release}
%description -n cta-rmcd
CERN Tape Archive:
The Remote Media Changer daemon (rmcd)
%files -n cta-rmcd
%defattr(-,root,root)
%attr(0644,root,root) %config(noreplace) /etc/logrotate.d/cta-rmcd
%attr(0644,root,root) %doc /usr/share/man/man1/cta-rmcd.1cta.gz
%attr(0755,root,root) %{_bindir}/cta-rmcd
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/cta/cta-rmcd.conf.example
%attr(0644,root,root) %config(noreplace) /etc/sysconfig/cta-rmcd
%attr(0644,root,root) /etc/systemd/system/cta-rmcd.service

%post -n cta-rmcd
%systemd_post cta-rmcd.service
%systemdDaemonReload
%systemdTryRestart cta-rmcd.service

%preun -n cta-rmcd
%systemd_preun cta-rmcd.service

%postun -n cta-rmcd
%systemd_postun cta-rmcd.service
%systemdDaemonReload

%posttrans -n cta-rmcd
MISSING_CONF=%{_sysconfdir}/cta/cta-rmcd.conf
if [[ ! -f "${MISSING_CONF}" ]] && [[ -f "${MISSING_CONF}.rpmsave" ]]
then
  mv ${MISSING_CONF}.rpmsave ${MISSING_CONF}
fi

%package -n cta-smc
Summary: The client of the Remote Media Changer Daemon (rmcd)
Group: Application/CTA
%description -n cta-smc
CERN Tape Archive:
The client of the Remote Media Changer Daemon (rmcd)
%files -n cta-smc
%defattr(-,root,root)
%attr(0755,root,root) %{_bindir}/cta-smc
%attr(0644,root,root) %doc /usr/share/man/man1/cta-smc.1cta.gz

%posttrans -n cta-smc
MISSING_CONF=%{_sysconfdir}/cta/cta-smc.conf
if [[ ! -f "${MISSING_CONF}" ]] && [[ -f "${MISSING_CONF}.rpmsave" ]]
then
  mv ${MISSING_CONF}.rpmsave ${MISSING_CONF}
fi

%package -n cta-tape-label
Summary: The command-line tool for pre-labelling a CTA tape.
Group: Application/CTA
Requires: cta-lib = %{version}-%{release}
Requires: xrootd-client-libs >= %{xrootdVersion}
Requires(post): /usr/sbin/setcap
%description -n cta-tape-label
CERN Tape Archive:
The command-line tool for pre-labelling a CTA tape.
%files -n cta-tape-label
%defattr(-,root,root)
%attr(0750,cta,tape) %{_bindir}/cta-tape-label
%attr(0644,root,root) %doc /usr/share/man/man1/cta-tape-label.1cta.gz
%post -n cta-tape-label
/usr/sbin/setcap cap_sys_rawio+ep  %{_bindir}/cta-tape-label

%package -n cta-readtp
Summary: The command-line tool for reading files from a CTA tape.
Group: Application/CTA
Requires: cta-lib = %{version}-%{release}
Requires: xrootd-client-libs >= %{xrootdVersion}
Requires(post): /usr/sbin/setcap
%description -n cta-readtp
CERN Tape Archive:
The command-line tool for reading files from a CTA tape.
%files -n cta-readtp
%defattr(-,root,root)
%attr(4750,cta,tape) %{_bindir}/cta-readtp
%attr(0644,root,root) %doc /usr/share/man/man1/cta-readtp.1cta.gz
%post -n cta-readtp
/usr/sbin/setcap cap_sys_rawio+ep  %{_bindir}/cta-readtp

%package -n cta-common
Summary: CERN Tape Archive common items
Group: Application/CTA
Requires(pre): /usr/bin/egrep, /usr/sbin/groupadd, /usr/sbin/luseradd
%description -n cta-common
CERN Tape Archive:
Common items such as the creation of the cta local user and /var/log/cta
%pre -n cta-common
/usr/bin/egrep -q '^cta:' /etc/passwd || /usr/sbin/luseradd -s /bin/nologin -c "CTA system account" -g tape cta
%files -n cta-common
%defattr(-,root,root)
%attr(0755,cta,tape) %dir /var/log/cta

%package -n cta-fst-gcd
Summary: Tape aware garbage collector daemon to run on an EOS FST
Group: Application/CTA
Requires: eos-client
Requires: python
%description -n cta-fst-gcd
cta-fst-gcd is a daemon that runs on an EOS FST and garbage
collects EOS disk copies that have been safely stored to tape.
%files -n cta-fst-gcd
%defattr(-,root,root)
%attr(0755,root,root) %{_bindir}/cta-fst-gcd
%attr(0644,root,root) %doc /usr/share/man/man1/cta-fst-gcd.1cta.gz
%attr(0644,root,root) %config(noreplace) /etc/systemd/system/cta-fst-gcd.service
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/cta/cta-fst-gcd.conf.example
%post -n cta-fst-gcd
%systemd_post cta-fst-gcd.service
%systemdDaemonReload
%systemdTryRestart cta-fst-gcd.service

%preun -n cta-fst-gcd
%systemd_preun cta-fst-gcd.service

%postun -n cta-fst-gcd
%systemd_postun cta-fst-gcd.service
%systemdDaemonReload

%package -n cta-release
Summary: Repository configuration for CTA and its dependencies
Group: Application/CTA
Requires: yum-plugin-versionlock
Requires: yum-plugin-priorities
Requires: python
Requires: jq
%description -n cta-release
Repository configuration for CTA and its dependencies
This package contains .repo files, gpg keys and yum-versionlock configuration for CTA
%files -n cta-release
%defattr(-,root,root)
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/yum.repos.d/*
%attr(0644,root,root) %{_sysconfdir}/pki/rpm-gpg/*
%attr(0644,root,root) %{_sysconfdir}/yum/pluginconf.d/versionlock.cta
%attr(0644,root,root) %{_sysconfdir}/cta/cta-release.conf
%attr(0755,root,root) %{_bindir}/cta-versionlock

%post -n cta-release
# Add CTA version to cta-release.conf file
cta_major_version=$(echo "%{ctaVersion}" | cut -d '.' -f 1)
echo $(jq --argjson CTA_MAJOR_VERSION $cta_major_version '. += {"cta_major_version": $CTA_MAJOR_VERSION}' %{_sysconfdir}/cta/cta-release.conf) > %{_sysconfdir}/cta/cta-release.conf

%preun -n cta-release
/usr/bin/cta-versionlock config eos4
/usr/bin/cta-versionlock remove
/usr/bin/cta-versionlock config eos5
/usr/bin/cta-versionlock remove


%changelog
* Tue Nov 14 2023 Joao Afonso <joao.afonso@cern.ch> - 4.10.8-1
- Various fixes and improvements to CTA
- Updates EOS version in CI to 4.8.105/5.1.28
- See ReleaseNotes.md for details

* Wed Oct 18 2023 Joao Afonso <joao.afonso@cern.ch> - 4.10.7-1
- Various fixes and improvements to CTA
- Updates EOS version in CI to 4.8.105/5.1.29
- See ReleaseNotes.md for details

* Fri Oct 13 2023 Jorge Camarero Vera <jorge.camarero@cern.ch> - 4.10.6-1
- Remove critical constrain after update heartbeat

* Mon Sep 25 2023 Jorge Camarero Vera <jorge.camarero@cern.ch> - 4.10.5-1
- Workaround for scheduler crashing

* Mon Sep 18 2023 Jorge Camarero Vera <jorge.camarero@cern.ch> - 4.10.4-1
- Bump "filesWrittenToTape: File size mismatch" error to ALERT

* Wed Sep 06 2023 Jorge Camarero Vera <jorge.camarero@cern.ch> - 4.10.3-1
- Fix device statistics from LTO drives

* Tue Sep 05 2023 Jorge Camarero Vera <jorge.camarero@cern.ch> - 4.10.2-1
- Fix scheduler crashing because of empty tape pool name
- See ReleaseNotes.md for details

* Tue Aug 08 2023 Joao Afonso <joao.afonso@cern.ch> - 4.10.1-1
- Various fixes and improvements to CTA
- See ReleaseNotes.md for details

* Mon Aug 07 2023 Joao Afonso <joao.afonso@cern.ch> - 4.10.0-2
- Removes any usage of the CTA catalogue version 13.0
- The migration should be done directly from version 12.0 to 14.0

* Mon Jul 24 2023 Joao Afonso <joao.afonso@cern.ch> - 4.10.0-1
- Catalogue schema version 14.0

* Mon Jul 03 2023 Joao Afonso <joao.afonso@cern.ch> - 4.9.0-1
- Catalogue schema version 13.0 re-tagging
- Same behaviour as 4.8.10-2

* Mon Jul 03 2023 Joao Afonso <joao.afonso@cern.ch> - 4.8.10-2
- Fix schema verification failure for postgres migration to catalogue v13

* Mon Jun 12 2023 Joao Afonso <joao.afonso@cern.ch> - 4.8.10-1
- Do not fail CTA taped when using older catalogue schema versions

* Wed Jun 07 2023 Joao Afonso <joao.afonso@cern.ch> - 4.8.9-1
- Catalogue schema version 13.0

* Wed May 31 2023 Jorge Camarero Vera <jorge.camarero@cern.ch> - 4.8.8-2
- Fix tagging release CI script for xrootd5
- See ReleaseNotes.md for details

* Wed May 31 2023 Joao Afonso <joao.afonso@cern.ch> - 4.8.8-1
- Enabled HTTP and EOSTOKEN support on CTA CI
- Change in tape server encryption logic
- Various fixes and improvements to CTA
- See ReleaseNotes.md for details

* Wed Mar 29 2023 Joao Afonso <joao.afonso@cern.ch> - 4.8.7-1
- Various fixes and improvements to CTA
- See ReleaseNotes.md for details

* Wed Mar 08 2023 Joao Afonso <joao.afonso@cern.ch> - 4.8.6-1
- Fixes queue cleanup bug in CTA
- See ReleaseNotes.md for details

* Thu Feb 16 2023 Joao Afonso <joao.afonso@cern.ch> - 4.8.5-1
- Various fixes and improvements to CTA
- See ReleaseNotes.md for details

* Tue Jan 24 2023 Joao Afonso <joao.afonso@cern.ch> - 4.8.4-1
- Major reduction of the number of DB queries issued to the CTA catalogue
- See ReleaseNotes.md for more details

* Wed Jan 18 2023 Joao Afonso <joao.afonso@cern.ch> - 4.8.3-1
- Added DB query counters for profiling purposes
- See ReleaseNotes.md for more details

* Wed Dec 14 2022 Joao Afonso <joao.afonso@cern.ch> - 4.8.2-1
- Improvements on catalogue DB query performance
- See ReleaseNotes.md for more details

* Mon Dec 12 2022 Joao Afonso <joao.afonso@cern.ch> - 4.8.1-1
- Fixes bug with protobuf definition
- See ReleaseNotes.md for more details

* Mon Nov 28 2022 Joao Afonso <joao.afonso@cern.ch> - 4.8.0-1
- This CTA release contains significant changes related to repacking, including the addition of new final and temporary states
- Minor fixes and improvements to CTA
- See ReleaseNotes.md for details

* Wed Nov 16 2022 Joao Afonso <joao.afonso@cern.ch> - 4.7.14-1
- Fixes to CTA and cta-admin tool, see ReleaseNotes.md for details

* Tue Nov 15 2022 Joao Afonso <joao.afonso@cern.ch> - 4.7.13-3
- Repackaging CTA for easy installation of public RPMs

* Tue Nov 08 2022 Jorge Camarero Vera <jorge.camarero@cern.ch> - 4.7.13-2
- Fix gitlab release tagging pipeline

* Mon Nov 07 2022 Jorge Camarero Vera <jorge.camarero@cern.ch> - 4.7.13-1
- Various fixes and improvements to CTA, see ReleaseNotes.md for details
- Change Owner Identifier in the header of Tapes
- Tool to update the storage class

* Thu Oct 27 2022 Joao Afonso <joao.afonso@cern.ch> - 4.7.12-2
- Repackaging CTA for easy installation of public RPMs

* Tue Oct 04 2022 Joao Afonso <joao.afonso@cern.ch> - 4.7.12-1
- Various fixes and improvements to CTA, see ReleaseNotes.md for details
- Performance improvement: optimized DB queries for getting tape drive states
- Upgrade eos5 to 5.1.1-1

* Fri Sep 16 2022 Joao Afonso <joao.afonso@cern.ch> - 4.7.11-1
- Various fixes and improvements to CTA, see ReleaseNotes.md for details
- Enabled build option without Oracle dependencies
- When using Spectra Logic libraries, this release requires Spectra Logic firmware version >= BlueScale12.8.08.0

* Tue Sep 13 2022 Joao Afonso <joao.afonso@cern.ch> - 4.7.10-1
- Catalogue schema version 12.0

* Mon Aug 08 2022 Julien Leduc <julien.leduc@cern.ch> - 4.7.9-2
- Fixes packaging issue upgrading from CTA 4.7.8-1 to 4.7.9-1

* Wed Aug 03 2022 Joao Afonso <joao.afonso@cern.ch> - 4.7.9-1
- Various fixes and improvements to CTA, see ReleaseNotes.md for details
- Changes to options and default values for cta-taped
- Updates EOS 5 versionlock for xrootd5 in CI to 5.0.25
- Updates versionlock for xrootd5 in CI to 5.4.4

* Tue Jul 12 2022 Joao Afonso <joao.afonso@cern.ch> - 4.7.8-1
- Catalogue schema version 11.0

* Fri Jul 01 2022 Joao Afonso <joao.afonso@cern.ch> - 4.7.7-1
- Fixes scheduling bug introduced in 4.7.6-1 and adds support for multiple tape label formats
- Updates EOS 5 version in CI to 5.0.25
- See ReleaseNotes.md for more details

* Tue Jun 21 2022 Joao Afonso <joao.afonso@cern.ch> - 4.7.6-1
- Improvements to the drive handler and other features, see ReleaseNotes.md for details
- Updates EOS version in CI to 4.8.86
- Removes CASTOR to CTA migration tools RPM

* Wed Jun 08 2022 Miguel Barros <miguel.veloso.barros@cern.ch> - 4.7.5-1
- Peformance related bug fix, see ReleaseNotes.md for detail

* Wed Jun 08 2022 Miguel Barros <miguel.veloso.barros@cern.ch> - 4.7.4-1
- Improvements to cta-tape-label and cta-verify-file, see ReleaseNotes.md for detail

* Wed Jun 08 2022 Miguel Barros <miguel.veloso.barros@cern.ch> - 4.7.3-1
- Bug fixes for tapeserver archive and retrieve mount logic, see ReleaseNotes.md for detail

* Tue May 10 2022 Volodymyr Yurchenko <volodymyr.yurchenko@cern.ch> - 4.7.2-1
- This release is deprecated, replaced by release v4.7.3-1

* Tue May 10 2022 Julien Leduc <julien.leduc@cern.ch> - 4.7.1-1
- Various code quality improvements, see ReleaseNotes.md for detail

* Tue Apr 26 2022 Miguel Barros <miguel.veloso.barros@cern.ch> - 4.7.0-1
- Catalogue schema version 10.0

* Thu Mar 17 2022 mvelosob <miguel.veloso.barros@cern.ch> - 4.6.1-1
- Catalogue schema version 4.6

* Fri Feb 11 2022 Michael Davis <michael.davis@cern.ch> - 4.6.0-1
- Catalogue schema version 4.5
- Updates EOS version in CI to 4.8.75

* Fri Jan 21 2022 mvelosob <miguel.veloso.barros@cern.ch> - 4.5.1-1
- Fix disk space reservation logic (cta/CTA#1101)

* Tue Jan 18 2022 Jorge Camarero Vera <jorge.camarero@cern.ch> - 4.5.0-1
- Improve cta-versionlock script
- Fixes to Drive State (cta/CTA#1091, cta/CTA#501)

* Fri Dec 10 2021 Julien Leduc <julien.leduc@cern.ch> - 4.4.0-1
- Removes support for MySQL
- Updates EOS to version 4.8.67
- Updates Ceph to version 15.2.15
- Build CTA with GCC 8.x (C++17) and fix deprecated code
- New cta-restore-deleted-files command

* Mon Nov 15 2021 Julien Leduc <julien.leduc@cern.ch> - 4.3-3
- Various bug fixes, see ReleaseNotes.md for detail

* Fri Oct 22 2021 Jorge Camarero Vera <jorge.camarero@cern.ch> - 4.3-2
- Various bug fixes, see ReleaseNotes.md for detail

* Thu Sep 30 2021 Jorge Camarero Vera <jorge.camarero@cern.ch> - 4.3-1
- Moves Drive Status from objectstore to Catalogue DB

* Fri Sep 03 2021 Jorge Camarero Vera <jcamarerov@gmail.com> - 4.2-3
- Catalogue schema version 4.2
- New command `cta-readtp` allows reading files from tape and verifying their checksum

* Wed Sep 01 2021 Jorge Camarero Vera <jorge.camarero@cern.ch> - 4.2-2
- See ReleaseNotes.md for detail of this release

* Wed Sep 01 2021 Miguel Barros <miguel.veloso.barros@cern.ch> - 4.2-1
- See ReleaseNotes.md for detail of this release

* Wed Aug 18 2021 Jorge Camarero Vera <jorge.camarero@cern.ch> - 4.1-1
- Add cta-release package for binary RPM distribution
- Add external encryption script option

* Tue Jul 27 2021 Steven Murray <Steven.Murray@cern.ch> - 4.0-5
- Adds a default mount rule

* Fri Jul 09 2021 Michael Davis <michael.davis@cern.ch> - 4.0-4
- Do not requeue report jobs when reportType is NoReportRequired (cta/CTA#1002)

* Mon Jul 05 2021 Julien Leduc <julien.leduc@cern.ch> - 4.0-3
- Updates Ceph to version 14.2.20
- Adds tape verification tool (cta-verify-file) to cta-cli RPM

* Tue Jun 01 2021 Julien Leduc <julien.leduc@cern.ch> - 4.0-2
- Updates EOS to 4.8.45
- Updates eos-xrootd to 4.12.8

* Fri Feb 05 2021 Cedric Caffy <cedric.caffy@cern.ch> - 4.0-1
- Oracle catalogue migration scripts 3.1to3.2.sql: replaced DELETE FROM table_name by TRUNCATE TABLE table_name

* Wed Feb 03 2021 Cedric Caffy <cedric.caffy@cern.ch> - 3.2-1
- Updates EOS to 4.8.37-1

* Fri Jan 15 2021 Cedric Caffy <cedric.caffy@cern.ch> - 3.1-14
- Updates EOS to 4.8.35-1

* Thu Jan 07 2021 Cedric Caffy <cedric.caffy@cern.ch> - 3.1-13
- Updates EOS to 4.8.34-1
- Updates XRootD to 4.12.6-1

* Fri Dec 04 2020 Julien Leduc <julien.leduc@cern.ch> - 3.1-12
- Updates EOS to 4.8.30-1

* Wed Dec 02 2020 Julien Leduc <julien.leduc@cern.ch> - 3.1-11
- Updates EOS to 4.8.29-1

* Thu Nov 12 2020 Cedric Caffy <cedric.caffy@cern.ch> - 3.1-10
- See ReleaseNotes.md for detail of this release

* Fri Nov 06 2020 Cedric Caffy <cedric.caffy@cern.ch> - 3.1-9
- Updates EOS to 4.8.26-1

* Mon Oct 26 2020 Volodymyr Yurchenko <volodymyr.yurchenko@cern.ch> - 3.1-8
- Implements software Recommended Access Order (RAO) for LTO-8 drives
- Upstream EOS 4.8.24-1
- Upstream XRootD to 4.12.5-1

* Wed Sep 23 2020 Cedric Caffy <cedric.caffy@cern.ch> - 3.1-7
- See ReleaseNotes.md for detail of this release

* Mon Sep 21 2020 Cedric Caffy <cedric.caffy@cern.ch> - 3.1-6
- Upstream EOS 4.8.15-1
- Upstream XRootD 4.12.4-1
- cta/CTA#890 CTA RPMs should only use the XRootD-client-libs package

* Thu Aug 20 2020 Julien Leduc <julien.leduc@cern.ch> - 3.1-5
- See ReleaseNotes.md for detail of this release
- Prohibit SQLite from being used as the CTA catalogue database backend
- Corrects contents and dependencies of cta-lib-catalogue RPM

* Fri Aug 07 2020 Steven Murray <Steven.Murray@cern.ch> - 3.1-4
- Removes dependency between cta-migration-tools RPM and librados2

* Fri Jul 31 2020 Julien Leduc <julien.leduc@cern.ch> - 3.1-3
- Upstream EOS 4.8.10-1

* Fri Jul 17 2020 Steven Murray <Steven.Murray@cern.ch> - 3.1-2
- Added database upgrade/changelog script for schema v3.1

* Thu Jul 16 2020 Cedric Caffy <cedric.caffy@cern.ch> - 3.1-1
- Catalogue schema version 3.1

* Wed Jun 24 2020 Cedric Caffy <cedric.caffy@cern.ch> - 3.0-3
- Bug fix to cta-statistics-update tool

* Wed Jun 24 2020 Julien Leduc <julien.leduc@cern.ch> - 3.0-2
- Upstream EOS 4.8.3-1
- Upstream XRootD 4.12.3-1

* Fri Jun 19 2020 Julien Leduc <julien.leduc@cern.ch> - 3.0-1
- EOS 4.8.2-1
- XRootD 4.12.1-1
- Catalogue schema version 3.0

* Mon May 04 2020 Julien Leduc <julien.leduc@cern.ch> - 2.0-5
- Upstream EOS 4.7.12-1

* Tue Apr 28 2020 Steven Murray <Steven.Murray@cern.ch> - 2.0-4
- See ReleaseNotes.md for detail of this release

* Wed Apr 15 2020 Julien Leduc <julien.leduc@cern.ch> - 2.0-3
- Upstream EOS 4.7.9-1

* Wed Apr 08 2020 Julien Leduc <julien.leduc@cern.ch> - 2.0-2
- EOS 4.7.8-1
- XRootD 4.11.3-1
- Ceph Nautilus 14.2.8-0

* Sat Mar 14 2020 Julien Leduc <julien.leduc@cern.ch> - 2.0-1
- Catalogue schema version 2.0
- EOS 4.6.7-1
- XRootD 4.11.2-1

* Fri Feb 21 2020 Julien Leduc <julien.leduc@cern.ch> - 1.2-0
- Upgrade the catalogue schema from version 1.0 to 1.1 before updating CTA components
- Adds a new schema verification tool (cta-catalogue-schema-verify)
- Adds a new tape statistic updater tool (cta-statistics-update)

* Fri Jan 10 2020 Steven Murray <Steven.Murray@cern.ch> - 1.0-3
- Release 1.0-3

* Mon Jan 06 2020 Steven Murray <Steven.Murray@cern.ch> - 1.0-2
- Release 1.0-2

* Mon Dec 09 2019 Cedric CAFFY <cedric.caffy@cern.ch> - 1.0-1
- Release 1.0-1
