specfile: change /etc/shells only when (un)installing the package

Confirms now to: https://fedoraproject.org/wiki/Packaging:Scriptlets#Shells
This commit is contained in:
David Kaspar [Dee'Kej] 2016-09-01 14:40:22 +02:00
parent 40ec3882a1
commit fa9ea15325

View File

@ -14,6 +14,7 @@ Provides: /bin/tcsh
Requires(post): grep
Requires(postun): grep
Requires(postun): coreutils
Requires(postun): sed
BuildRequires: autoconf
BuildRequires: automake
BuildRequires: gettext-devel
@ -160,27 +161,30 @@ make check
%post
if [ ! -f /etc/shells ]; then
echo "%{_bindir}/tcsh" >> /etc/shells
echo "/bin/tcsh" >> /etc/shells
echo "%{_bindir}/csh" >> /etc/shells
echo "/bin/csh" >> /etc/shells
# Add login shell entries to /etc/shells only when installing the package
# for the first time (see 'man 5 SHELLS' for more info):
if [[ "$1" -eq 1 ]]; then
if [[ ! -f %{_sysconfdir}/shells ]]; then
echo "/bin/csh" >> %{_sysconfdir}/shells
echo "/bin/tcsh" >> %{_sysconfdir}/shells
echo "%{_bindir}/csh" >> %{_sysconfdir}/shells
echo "%{_bindir}/tcsh" >> %{_sysconfdir}/shells
else
grep -q '^%{_bindir}/tcsh$' /etc/shells || echo "%{_bindir}/tcsh" >> /etc/shells
grep -q '^/bin/tcsh$' /etc/shells || echo "/bin/tcsh" >> /etc/shells
grep -q '^%{_bindir}/csh$' /etc/shells || echo "%{_bindir}/csh" >> /etc/shells
grep -q '^/bin/csh$' /etc/shells || echo "/bin/csh" >> /etc/shells
grep -q "^/bin/csh$" %{_sysconfdir}/shells || echo "/bin/csh" >> %{_sysconfdir}/shells
grep -q "^/bin/tcsh$" %{_sysconfdir}/shells || echo "/bin/tcsh" >> %{_sysconfdir}/shells
grep -q "^%{_bindir}/csh$" %{_sysconfdir}/shells || echo "%{_bindir}/csh" >> %{_sysconfdir}/shells
grep -q "^%{_bindir}/tcsh$" %{_sysconfdir}/shells || echo "%{_bindir}/tcsh" >> %{_sysconfdir}/shells
fi
fi
%postun
if [ ! -x %{_bindir}/tcsh ]; then
grep -v '^%{_bindir}/tcsh$' /etc/shells | \
grep -v '^%{_bindir}/csh$' > /etc/shells.rpm && \
grep -v '^/bin/tcsh$' /etc/shells | \
grep -v '^%{_bindir}/csh$' | \
grep -v '^/bin/csh$' > /etc/shells.rpm && \
mv /etc/shells.rpm /etc/shells
# Remove the login shell lines from /etc/shells only when uninstalling:
if [[ "$1" -eq 0 && -f %{_sysconfdir}/shells ]]; then
sed -i -e '\!^/bin/csh$!d' %{_sysconfdir}/shells
sed -i -e '\!^/bin/tcsh$!d' %{_sysconfdir}/shells
sed -i -e '\!^%{_bindir}/csh$!d' %{_sysconfdir}/shells
sed -i -e '\!^%{_bindir}/tcsh$!d' %{_sysconfdir}/shells
fi