Name:          authselect
Version:       1.8.0
Release:       3
Summary:       A tool to select system authentication and identity sources from a list of supported profiles
License:       GPL-3.0-or-later
URL:           https://github.com/authselect/authselect
Source0:       https://github.com/authselect/authselect/archive/%{version}/%{name}-%{version}.tar.gz
Source1:       authselect.conf

Patch1:    0001-Fix-segfault-in-sub-command-requirements-and-test.patch

BuildRequires: autoconf gettext-devel automake libtool popt-devel libcmocka-devel
BuildRequires: m4 gcc po4a asciidoc python3-devel
BuildRequires: libselinux-devel
Requires:      grep sed systemd gawk coreutils findutils pam >= 1.3.1
Obsoletes:     authselect-libs < %{version}-%{release}
Obsoletes:     authselect-compat < 1.5.1
Provides:      authselect-libs = %{version}-%{release}
%{?systemd_requires}

%description
Authselect is designed to be a replacement for authconfig (which is the default tool for this 
job on Fedora and RHEL based systems) but it takes a different approach to configure the system. 
Instead of letting the administrator build the PAM stack with a tool (which may potentially 
end up with a broken configuration), it would ship several tested stacks (profiles) that solve 
a use-case and are well tested and supported. At the same time, some obsolete features of 
authconfig would not be supported by authselect.

This package contains commands for selecting system identity and authentication sources, and
common library files for the authselect tool.

%package_help

%package devel
Summary:       Development library files and header files for the authselect tool
Requires:      authselect%{?_isa} = %{version}-%{release}

%description devel
This package contains development library files and headers for the authselect tool. This 
package is used to develop a front-end for the authselect library.

%prep
%autosetup -n %{name}-%{version} -p1

%build
autoreconf -ivf
%configure \
    --disable-static \
    --with-completion-dir=%{bash_completions_dir} \
    --with-pythonbin=%{__python3}

%make_build

%install
%make_install
%delete_la

%__install -m 644 -D %{S:1} %{buildroot}%{_datadir}/authselect/authselect.conf

rm -fr %{buildroot}%{_datadir}/doc/%{name}

%find_lang %{name}

%find_lang %{name}-help --with-man --all-name --without-mo

%check
%make_build check

%post
%systemd_post authselect-apply-changes.service authselect-first-boot.service

%posttrans
# Keep nss-altfiles for all rpm-ostree based systems.
# See https://github.com/authselect/authselect/issues/48
if test -e /run/ostree-booted; then
    for PROFILE in `ls %{_datadir}/authselect/default`; do
        %{_bindir}/authselect create-profile $PROFILE --vendor --base-on $PROFILE --symlink-pam --symlink-dconf --symlink=REQUIREMENTS --symlink=README &> /dev/null
        %__sed -i -e 's/{if "with-altfiles":\([^}]\+\)}/\1/g' %{_datadir}/authselect/vendor/$PROFILE/nsswitch.conf &> /dev/null
    done
fi

# On a new installation skip the upgrade migration below.
# openEuler does not enable authselect by default, the pam provided
# configuration is kept intact, users enable authselect on their own.
if [ $1 == 1 ] ; then
    exit 0
fi

# Minimal profile was removed. Switch to local during upgrade.
%__sed -i '1 s/^minimal$/local/'  %{_sysconfdir}/authselect/authselect.conf > /dev/null 2>&1
for file in  %{_sysconfdir}/authselect/custom/*/*; do
    link=`%{_bindir}/readlink "$file"`
    if [[ "$link" == %{_datadir}/authselect/default/minimal/* ]]; then
        target=`%{_bindir}/basename "$link"`
        %{_bindir}/ln -sfn "%{_datadir}/authselect/default/local/$target" "$file"
    fi
done

# We might have add vendor profiles, compute new profiles checksum
%{_bindir}/find "%{_datadir}/authselect" -mindepth 2 -type f \
    -printf "%%P\n" -exec %{_bindir}/sha256sum {} + | %{_bindir}/sha256sum \
    > "%{_datadir}/authselect/checksum"

# Apply any changes to profiles (validates configuration first internally)
%{_bindir}/authselect apply-changes &> /dev/null

exit 0

%preun
%systemd_preun authselect-apply-changes.service authselect-first-boot.service
if [ $1 == 0 ] ; then
    # Remove authselect symbolic links so all authselect files can be
    # deleted safely. If this fail, the uninstallation must fail to avoid
    # breaking the system by removing PAM files. However, the command can
    # only fail if it can not write to the file system.
    %{_bindir}/authselect opt-out
fi

%postun
%systemd_postun authselect-apply-changes.service authselect-first-boot.service

%files -f %{name}.lang
%license COPYING
%doc README.md
%{_bindir}/authselect
%{bash_completions_dir}/*
%dir %{_sysconfdir}/authselect
%dir %{_sysconfdir}/authselect/custom
%ghost %attr(0644,root,root) %{_sysconfdir}/authselect/authselect.conf
%ghost %attr(0644,root,root) %{_sysconfdir}/authselect/dconf-db
%ghost %attr(0644,root,root) %{_sysconfdir}/authselect/dconf-locks
%ghost %attr(0644,root,root) %{_sysconfdir}/authselect/fingerprint-auth
%ghost %attr(0644,root,root) %{_sysconfdir}/authselect/nsswitch.conf
%ghost %attr(0644,root,root) %{_sysconfdir}/authselect/password-auth
%ghost %attr(0644,root,root) %{_sysconfdir}/authselect/postlogin
%ghost %attr(0644,root,root) %{_sysconfdir}/authselect/smartcard-auth
%ghost %attr(0644,root,root) %{_sysconfdir}/authselect/system-auth
%ghost %attr(0644,root,root) %{_sysconfdir}/nsswitch.conf
%ghost %attr(0644,root,root) %{_sysconfdir}/pam.d/fingerprint-auth
%ghost %attr(0644,root,root) %{_sysconfdir}/pam.d/password-auth
%ghost %attr(0644,root,root) %{_sysconfdir}/pam.d/postlogin
%ghost %attr(0644,root,root) %{_sysconfdir}/pam.d/smartcard-auth
%ghost %attr(0644,root,root) %{_sysconfdir}/pam.d/system-auth
%dir %{_localstatedir}/lib/authselect
%ghost %attr(0755,root,root) %{_localstatedir}/lib/authselect/backups/
%dir %{_datadir}/authselect
%dir %{_datadir}/authselect/vendor
%dir %{_datadir}/authselect/default
%dir %{_datadir}/authselect/default/local/
%dir %{_datadir}/authselect/default/sssd/
%dir %{_datadir}/authselect/default/winbind/
%config(noreplace) %{_datadir}/authselect/authselect.conf
%verify(not md5 size mtime) %{_datadir}/authselect/checksum
%{_datadir}/authselect/default/local/dconf-db
%{_datadir}/authselect/default/local/dconf-locks
%{_datadir}/authselect/default/local/fingerprint-auth
%{_datadir}/authselect/default/local/nsswitch.conf
%{_datadir}/authselect/default/local/password-auth
%{_datadir}/authselect/default/local/postlogin
%{_datadir}/authselect/default/local/README
%{_datadir}/authselect/default/local/REQUIREMENTS
%{_datadir}/authselect/default/local/smartcard-auth
%{_datadir}/authselect/default/local/switchable-auth
%{_datadir}/authselect/default/local/system-auth
%{_datadir}/authselect/default/sssd/dconf-db
%{_datadir}/authselect/default/sssd/dconf-locks
%{_datadir}/authselect/default/sssd/fingerprint-auth
%{_datadir}/authselect/default/sssd/nsswitch.conf
%{_datadir}/authselect/default/sssd/password-auth
%{_datadir}/authselect/default/sssd/postlogin
%{_datadir}/authselect/default/sssd/README
%{_datadir}/authselect/default/sssd/REQUIREMENTS
%{_datadir}/authselect/default/sssd/smartcard-auth
%{_datadir}/authselect/default/sssd/switchable-auth
%{_datadir}/authselect/default/sssd/system-auth
%{_datadir}/authselect/default/winbind/dconf-db
%{_datadir}/authselect/default/winbind/dconf-locks
%{_datadir}/authselect/default/winbind/fingerprint-auth
%{_datadir}/authselect/default/winbind/nsswitch.conf
%{_datadir}/authselect/default/winbind/password-auth
%{_datadir}/authselect/default/winbind/postlogin
%{_datadir}/authselect/default/winbind/README
%{_datadir}/authselect/default/winbind/REQUIREMENTS
%{_datadir}/authselect/default/winbind/smartcard-auth
%{_datadir}/authselect/default/winbind/switchable-auth
%{_datadir}/authselect/default/winbind/system-auth
%{_libdir}/libauthselect.so.*
%{_unitdir}/authselect-apply-changes.service
%{_unitdir}/authselect-first-boot.service

%files devel
%{_includedir}/authselect.h
%{_libdir}/libauthselect.so
%{_libdir}/pkgconfig/authselect.pc

%files help -f %{name}-help.lang
%{_mandir}/man?/*

%changelog
* Thu Sep 10 2026 yixiangzhike <yixiangzhike007@163.com> - 1.8.0-3
- Fix segfault in sub command requirements and test
- Quiet for sed when authselect.conf not exist

* Tue Aug 25 2026 Funda Wang <fundawang@yeah.net> - 1.8.0-2
- Do not enable authselect by default on new installation, keep pam provided configuration

* Sat Aug 22 2026 Funda Wang <fundawang@yeah.net> - 1.8.0-1
- update to 1.8.0

* Sun Jul 12 2026 Funda Wang <fundawang@yeah.net> - 1.7.1-1
- update to 1.7.1
- compat pacakge dropped upstream

* Fri Jul 18 2025 Funda Wang <fundawang@yeah.net> - 1.5.0-3
- fix build with cmock 1.1.8
- cleanup spec

* Tue Jul 15 2025 liuzhilin <liuzhilin@kylinos.cn> - 1.5.0-2
- backport fix configure typo patch

* Mon Apr 1 2024 dongjiao <dongjiao@kylinos.cn> - 1.5.0-1
- Update to 1.5.0

* Mon Dec 18 2023 yixiangzhike <yixiangzhike007@163.com> - 1.4.3-1
- update to 1.4.3

* Tue Jan 17 2023 yixiangzhike <yixiangzhike007@163.com> - 1.4.2-1
- update to 1.4.2

* Mon Aug 15 2022 panxiaohe <panxh.life@foxmail.com> - 1.2.4-6
- cli: fix memory handling with new popt library

* Sun May 15 2022 yixiangzhike <yixiangzhike007@163.com> - 1.2.4-5
- provide default directory /etc/authselect

* Fri Apr 29 2022 yixiangzhike <yixiangzhike007@163.com> - 1.2.4-4
- delete duplicate file README.md from authselect-help

* Mon Mar 21 2022 yixiangzhike <yixiangzhike007@163.com> - 1.2.4-3
- fix change date for version 1.2.4-2 in changelog

* Fri Jan 14 2022 yixiangzhike <yixiangzhike007@163.com> - 1.2.4-2
- revert "remove authselect compat package"

* Thu Dec 30 2021 yixiangzhike <yixiangzhike007@163.com> - 1.2.4-1
- update to 1.2.4

* Mon Jul 19 2021 yixiangzhike <zhangxingliang3@huawei.com> - 1.2.2-3
- Delete unnecessary gdb from BuildRequires

* Thu Mar 25 2021 yangzhuangzhuang <yangzhuangzhuang1@huawei.com> - 1.2.2-2
- Delete the DLL of an earlier version

* Sat Jan 23 2021 yangzhuangzhuang <yangzhuangzhuang1@huawei.com> - 1.2.2-1
- update to 1.2.2

* Fri Jul 24 2020 Liquor <lirui130@huawei.com> - 1.2.1-1
- update to 1.2.1

* Tue Jun 02 2020 SimpleUpdate Robot <tc@openeuler.org>
- Update to version 1.1

* Tue Nov 5 2019 openEuler Buildteam <buildteam@openeuler.org> - 1.0.1-5
- Delete unused lang files

* Mon Sep 30 2019 openEuler Buildteam <buildteam@openeuler.org> - 1.0.1-4
- Fix conflict of authselect and authconfig

* Tue Sep 10 2019 openEuler Buildteam <buildteam@openeuler.org> - 1.0.1-3
- Package init