# COPR Ligenix's spec file for glpi-plugin-sccm
#
# Copyright (c) 2021-2023 Jean-Marc Liger
#
# License: CC-BY-SA
# http://creativecommons.org/licenses/by-sa/4.0/
#
# Please, preserve the changelog entries
#
%global pluginname sccm
%global glpi_min   10.0.0
%global glpi_max   10.1.0

Name:           glpi-plugin-%{pluginname}
Version:        2.4.3
Release:        1%{?dist}
Summary:        Plugin to synchronize data with Microsoft SCCM tool

License:        GPLv2+
URL:            https://github.com/pluginsGLPI/%{pluginname}

Source0:        https://github.com/pluginsGLPI/%{pluginname}/releases/download/v%{version}/glpi-%{pluginname}-%{version}.tar.bz2

BuildArch:      noarch
BuildRequires:  gettext

Requires:       php-sqlsrv
# from packages-microsoft-prod repo
Requires:       msodbcsql17
Requires:       unixODBC
%if 0%{?fedora} || 0%{?rhel} >= 8
Requires:      (glpi >= %{glpi_min} with glpi < %{glpi_max})
%else
Requires:       glpi >= %{glpi_min}
Requires:       glpi <  %{glpi_max}
%endif
Requires:       glpi-plugin-fusioninventory


%description
This plugin allows you synchronize computers from SCCM (version 1802) to GLPI.

It uses the "FusionInventory for GLPI" plugin and the power of its internal engine:
- The plugin integrates two automatic actions : "SCCMCollect" et "SCCMPush".
- The automatic action "SCCMCollect" queries the SCCM server with MsSQL queries.
- This same action builds an XML foreach computer (in FusionInventory format).
- The automatic action "SCCMPush" injects XML files into GLPI over HTTP(s)
  (via cURL and FusionInventory) to display computer in GLPI.

This is the same workflow that FusionInventory agent.


%prep
%setup -q -c

grep 'define("PLUGIN_SCCM_M.._GLPI' %{pluginname}/setup.php

# remove unused files
rm    %{pluginname}/%{pluginname}.xml
rm    %{pluginname}/composer.json

# move doc files
mkdir docs
mv %{pluginname}/README.md        docs/
mv %{pluginname}/SECURITY.md      docs/
mv %{pluginname}/screenshots/     docs/
mv %{pluginname}/glpi_network.png docs/

# create link to LICENSE for standard doc folder
ln -s %{_datadir}/glpi/plugins/%{pluginname}/LICENSE.md LICENSE.md


%build
# empty build


%install
mkdir -p %{buildroot}%{_localstatedir}/lib/glpi/files/_plugins/%{pluginname}

mkdir -p %{buildroot}/%{_datadir}/glpi/plugins
cp -ar %{pluginname} %{buildroot}/%{_datadir}/glpi/plugins/%{pluginname}

for i in %{buildroot}/%{_datadir}/glpi/plugins/%{pluginname}/locales/*
do
  lang=$(basename $i)
  echo "%lang(${lang:0:2}) %{_datadir}/glpi/plugins/%{pluginname}/locales/${lang}"
done | tee %{name}.lang


%files -f %{name}.lang
%{!?_licensedir:%global license %%doc}
%license LICENSE.md
%doc docs/*
%dir %{_datadir}/glpi/plugins/%{pluginname}
%dir %{_datadir}/glpi/plugins/%{pluginname}/locales
# LICENSE file required by installation process
%{_datadir}/glpi/plugins/%{pluginname}/LICENSE.md
%{_datadir}/glpi/plugins/%{pluginname}/*.php
%{_datadir}/glpi/plugins/%{pluginname}/front
%{_datadir}/glpi/plugins/%{pluginname}/inc
%{_datadir}/glpi/plugins/%{pluginname}/locales
%{_datadir}/glpi/plugins/%{pluginname}/vendor
# data
%attr(750,apache,root) %{_localstatedir}/lib/glpi/files/_plugins/%{pluginname}


%changelog
* Mon Jun 19 2023 Jean-Marc Liger <ligenix@iscp.fr> - 2.4.3-1
- Version 2.4.3

* Fri May 26 2023 Jean-Marc Liger <ligenix@iscp.fr> - 2.4.2-1
- Version 2.4.2

* Wed May 03 2023 Jean-Marc Liger <ligenix@iscp.fr> - 2.4.1-2
- Move screenshots to docs

* Mon May 01 2023 Jean-Marc Liger <ligenix@iscp.fr> - 2.4.1-1
- Version 2.4.1 for GLPI 10.0.x

* Mon May 01 2023 Jean-Marc Liger <ligenix@iscp.fr> - 2.3.2-1
- Version 2.3.2

* Tue Sep 20 2022 Jean-Marc Liger <ligenix@iscp.fr> - 2.3.1-1
- Version 2.3.1
- Security: Configuration page is accessible publicly in read-only mode (CVE-2021-39190)

* Mon May 17 2021 Jean-Marc Liger <ligenix@iscp.fr> - 2.3.0-1
- Initial RPM based on Remi Collet previous GLPI plugins spec files