## START: Set by rpmautospec
## (rpmautospec version 0.3.0)
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 3;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

# broken Makefile
%global _smp_mflags -j1

%global __provides_exclude_from ^%{_libdir}/security/.*\.so$

Name:           deepin-pw-check
Version:        5.1.8
Release:        %autorelease
Summary:        Tool used to check password and manager the configuration for password
# The entire code is GPLv3+ except
# lib/md5.c is Public Domain and
# lib/md5_crypt.c is Beerware
License:        GPLv3+ and Public Domain and Beerware
URL:            https://github.com/linuxdeepin/deepin-pw-check
Source0:        %{url}/archive/%{version}/%{name}-%{version}.tar.gz
Patch1:         0001-Adapt-to-Fedora-cracklib-API.patch
BuildRequires:  make
BuildRequires:  gcc
BuildRequires:  compiler(go-compiler)
BuildRequires:  golang(github.com/godbus/dbus)
BuildRequires:  golang(github.com/linuxdeepin/go-dbus-factory/org.freedesktop.policykit1)
BuildRequires:  golang(github.com/linuxdeepin/go-lib/dbusutil)
BuildRequires:  pam-devel
BuildRequires:  pkgconfig(gio-2.0)
BuildRequires:  pkgconfig(gdk-3.0)
BuildRequires:  deepin-gettext-tools
BuildRequires:  cracklib-devel
BuildRequires:  iniparser-devel
BuildRequires:  deepin-gir-generator

%description
In order to unify the authentication interface, this interface is designed to
adapt to fingerprint, face and other authentication methods.

%package devel
Summary: Header files and libraries used to build deepin-pw-check
Requires: %{name}%{?_isa} = %{version}-%{release}
Requires: cracklib-devel%{?_isa}
Requires: iniparser-devel%{?_isa}

%description devel
In order to unify the authentication interface, this interface is designed to
adapt to fingerprint, face and other authentication methods.

%prep
%autosetup -p1
sed -i -e 's|\${PREFIX}/lib/deepin-pw-check|${PREFIX}/libexec/deepin-pw-check|;  s|\${PREFIX}/lib$|\${PREFIX}/%{_lib}|; s|cp |cp -a |' Makefile
sed -i -e 's|/usr/lib|%{_libexecdir}|' misc/system-services/com.deepin.daemon.PasswdConf.service
sed -i -e 's|/usr/lib|%{_libdir}|' misc/pkgconfig/libdeepin_pw_check.pc

%build
# expand build_ldflags at %%build section, RHBZ#2044028
sed -i 's|gcc |gcc %{build_cflags} %{build_ldflags} |' Makefile

# manually build the deepin-pw-check command since it is hard to override
# Makefile with %%gobuild
make prepare
touch prepare
export GOPATH=%{gopath}
%gobuild -o out/bin/%{name} service/*.go

%make_build

%install
mkdir -p %{buildroot}/%{_sysconfdir}/deepin
export GOPATH=%{gopath}
export PKG_FILE_DIR=%{_libdir}/pkgconfig
%make_install PKG_FILE_DIR=%{_libdir}/pkgconfig PAM_MODULE_DIR=%{_libdir}/security
# don't install static library
rm -v %{buildroot}%{_libdir}/*.a

%find_lang deepin-pw-check

%files -f deepin-pw-check.lang
%doc README.md
%license LICENSE
%dir %{_sysconfdir}/deepin
%{_bindir}/pwd-conf-update
%{_libexecdir}/deepin-pw-check/
%{_libdir}/libdeepin_pw_check.so.1*
%{_libdir}/security/pam_deepin_pw_check.so
%{_datadir}/dbus-1/system-services/*.service
%{_datadir}/dbus-1/system.d/*.conf
%{_datadir}/polkit-1/actions/*.policy

%files devel
%{_libdir}/libdeepin_pw_check.so
%{_libdir}/pkgconfig/libdeepin_pw_check.pc
%{_includedir}/deepin_pw_check.h

%changelog
* Thu Jul 21 2022 Fedora Release Engineering <releng@fedoraproject.org> 5.1.8-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild

* Tue Jul 19 2022 Maxwell G <gotmax@e.email> 5.1.8-2
- Rebuild for
  CVE-2022-{1705,32148,30631,30633,28131,30635,30632,30630,1962} in golang

* Sat Jul 16 2022 Robin Lee <cheeselee@fedoraproject.org> 5.1.8-1
- New release 5.1.8

* Sat Jun 18 2022 Robert-André Mauchin <zebob.m@gmail.com> 5.1.6-3
- Rebuilt for CVE-2022-1996, CVE-2022-24675, CVE-2022-28327,
  CVE-2022-27191, CVE-2022-29526, CVE-2022-30629

* Fri Jun 17 2022 Robert-André Mauchin <zebob.m@gmail.com> 5.1.6-2
- Rebuilt for CVE-2022-1996, CVE-2022-24675, CVE-2022-28327,
  CVE-2022-27191, CVE-2022-29526, CVE-2022-30629

* Fri Feb 18 2022 Robin Lee <cheeselee@fedoraproject.org> 5.1.6-1
- New release 5.1.6 (RHBZ#2045308)

* Thu Jan 20 2022 Fedora Release Engineering <releng@fedoraproject.org> 5.1.2-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild

* Wed Jan 05 2022 Robin Lee <cheeselee@fedoraproject.org> 5.1.2-1
- New release 5.1.2

* Mon Sep 06 2021 Robin Lee <cheeselee@fedoraproject.org> 5.0.22-1
- Initial import