Use update-alternatives for man(1), apropos(1), whatis(1)

OBS-URL: https://build.opensuse.org/package/show/Base:System/man?expand=0&rev=94
This commit is contained in:
Dr. Werner Fink 2019-03-06 11:57:50 +00:00 committed by Git OBS Bridge
parent ad670e6734
commit a595279334
3 changed files with 59 additions and 22 deletions

View File

@ -1,3 +1,11 @@
-------------------------------------------------------------------
Wed Mar 6 11:47:58 UTC 2019 - Dr. Werner Fink <werner@suse.de>
- Use update-alternatives to allow that man(1), apropos(1), whatis(1)
can be overwritten by an other package like mandoc
- Reintroduce wrapper for man(1) but without mapping to user man to
be able to reset the PATH to the standard for any preprocessor
-------------------------------------------------------------------
Mon Nov 26 11:37:32 UTC 2018 - Dr. Werner Fink <werner@suse.de>

View File

@ -1,7 +1,7 @@
#
# spec file for package man
#
# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@ -21,8 +21,6 @@
%define _fillupdir /var/adm/fillup-templates
%endif
%bcond_with wrapman
Name: man
BuildRequires: automake
BuildRequires: flex
@ -37,6 +35,7 @@ BuildRequires: libzio-devel
BuildRequires: man-pages
BuildRequires: pkg-config
BuildRequires: po4a
BuildRequires: update-alternatives
BuildRequires: xz-devel
BuildRequires: zlib-devel
Version: 2.8.4
@ -58,6 +57,8 @@ Requires: groff >= 1.18
Requires: less
Requires(pre): user(man)
Requires(pre): group(man)
Requires(post): update-alternatives
Requires(preun): update-alternatives
Source: http://download.savannah.gnu.org/releases/man-db/man-db-%{version}.tar.xz
Source1: sysconfig.cron-man
Source2: cron.daily.do_mandb
@ -199,27 +200,30 @@ fi
%if %suse_version <= 1030
export MKDIR_P="mkdir -p"
%endif
rm -rf %{buildroot}%{_localstatedir}/cache/man
rm -rf %{buildroot}%{_localstatedir}/cache/man
mkdir -p %{buildroot}%{_datadir}/doc/packages/man
mkdir -p %{buildroot}%{_libexecdir}/man-db
mkdir -p %{buildroot}%{_bindir}
mkdir -p %{buildroot}/etc
mkdir -p %{buildroot}%{_mandir}
mkdir -p %{buildroot}%{_sysconfdir}/alternatives
make nls=all install DESTDIR=%{buildroot}
rm -vf %{buildroot}%{_libdir}/*.la
mv %{buildroot}%{_datadir}/doc/man-db/man-db-manual.* \
%{buildroot}%{_datadir}/doc/packages/man/
# wrapper which drops roots privileges if root executes man or mandb
if test -x %{buildroot}%{_bindir}/mandb ; then
mv %{buildroot}%{_bindir}/mandb %{buildroot}%{_libexecdir}/man-db/
install wrapper %{buildroot}%{_bindir}/mandb
fi
%if %{with wrapman}
if test -x %{buildroot}%{_bindir}/man ; then
mv %{buildroot}%{_bindir}/man %{buildroot}%{_libexecdir}/man-db/
ln -sf mandb %{buildroot}%{_bindir}/man
fi
%endif
mkdir -p %{buildroot}%{_mandir}
mv -vf %{buildroot}%{_bindir}/man %{buildroot}%{_libexecdir}/man-db/
mv -vf %{buildroot}%{_bindir}/mandb %{buildroot}%{_libexecdir}/man-db/
mv -vf %{buildroot}%{_bindir}/apropos %{buildroot}%{_libexecdir}/man-db/
mv -vf %{buildroot}%{_bindir}/whatis %{buildroot}%{_libexecdir}/man-db/
install wrapper %{buildroot}%{_libexecdir}/man-db/
ln -sf %{_libexecdir}/man-db/wrapper %{buildroot}%{_sysconfdir}/alternatives/man
ln -sf %{_libexecdir}/man-db/wrapper %{buildroot}%{_bindir}/mandb
ln -sf %{_libexecdir}/man-db/apropos %{buildroot}%{_sysconfdir}/alternatives/apropos
ln -sf %{_libexecdir}/man-db/whatis %{buildroot}%{_sysconfdir}/alternatives/whatis
ln -sf %{_sysconfdir}/alternatives/man %{buildroot}%{_bindir}/man
ln -sf %{_sysconfdir}/alternatives/apropos %{buildroot}%{_bindir}/apropos
ln -sf %{_sysconfdir}/alternatives/whatis %{buildroot}%{_bindir}/whatis
pushd %{buildroot}%{_mandir}/
rm -rf *.ascii/
for d in *.UTF-8 ; do
@ -274,12 +278,22 @@ test -d var/catman/ && rm -rf var/catman/ || true
%if 0%{suse_version} >= 1500
%service_add_post mandb.service mandb.timer
%endif
# Remark: soelim(1) is part of package groff or mandoc and
# makewhatis(8) is part of package makewaht or mandoc
%{_sbindir}/update-alternatives --quiet --force \
--install %{_bindir}/man man %{_libexecdir}/man-db/wrapper 1010 \
--slave %{_bindir}/apropos apropos %{_libexecdir}/man-db/apropos \
--slave %{_bindir}/whatis whatis %{_libexecdir}/man-db/whatis
%preun
%service_del_preun man-db-create.service
%if 0%{suse_version} >= 1500
%service_del_preun mandb.service mandb.timer
%endif
if test $1 -eq 0
then
%{_sbindir}/update-alternatives --quiet --remove man %{_bindir}/man
fi
%postun
/sbin/ldconfig
@ -300,20 +314,24 @@ test -d /var/cache/man && mandb --quiet --create ||:
%if 0%{suse_version} < 1500
%attr(0744,root,root) /etc/cron.daily/suse-do_mandb
%endif
%{_bindir}/apropos
%ghost %config %{_sysconfdir}/alternatives/man
%ghost %config %{_sysconfdir}/alternatives/apropos
%ghost %config %{_sysconfdir}/alternatives/whatis
%verify(not link mtime)%{_bindir}/man
%verify(not link mtime)%{_bindir}/apropos
%verify(not link mtime)%{_bindir}/whatis
%{_bindir}/mandb
%{_bindir}/catman
%{_bindir}/lexgrog
%{_bindir}/man
%{_bindir}/mandb
%{_bindir}/manpath
%{_bindir}/whatis
%dir %attr(0755,root,root) %{_libexecdir}/man-db
%if %{with wrapman}
%attr(0755,root,root) %{_libexecdir}/man-db/man
%endif
%attr(0755,root,root) %{_libexecdir}/man-db/apropos
%attr(0755,root,root) %{_libexecdir}/man-db/whatis
%attr(0755,root,root) %{_libexecdir}/man-db/mandb
%attr(0755,man,man) %{_libexecdir}/man-db/manconv
%attr(0755,man,man) %{_libexecdir}/man-db/globbing
%attr(0755,root,root) %{_libexecdir}/man-db/wrapper
%if 0%{suse_version} >= 1500
%attr(0744,man,man) %{_libexecdir}/man-db/do_mandb
%endif

View File

@ -67,6 +67,7 @@ char *program_name;
int main (int argc, char **argv, char *envp[])
{
extern char **environ;
uid_t ruid, euid;
gid_t rgid;
@ -87,6 +88,11 @@ int main (int argc, char **argv, char *envp[])
euid = geteuid();
rgid = getgid ();
/* The various preprocessors should be in standard path */
environ = envp;
setenv("PATH", "/bin:/usr/bin", 1);
envp = environ;
#ifdef DEBUG
printf ("%s:\n", program_name);
#endif
@ -101,6 +107,10 @@ int main (int argc, char **argv, char *envp[])
#ifdef DEBUG
printf ("%s\n", wlp->run);
#endif
if (strcmp("man", wlp->prog) == 0)
/* Short cut: do not map man command to an other user */
goto man;
if (ruid == 0 || euid == 0) {
static char *dummy_environ[] = { NULL };
extern char **environ;
@ -152,9 +162,10 @@ int main (int argc, char **argv, char *envp[])
setenv("USER", pwd->pw_name, 1);
setenv("LOGNAME", pwd->pw_name, 1);
if (cwd)
setenv("TERM", cwd, 1);
setenv("PWD", cwd, 1);
envp = environ;
}
man:
execve (wlp->run, argv, envp);
perror ("execve");
return -errno;