From fa9ea15325f05177919397ecfa56004cbf4eb2b1 Mon Sep 17 00:00:00 2001 From: "David Kaspar [Dee'Kej]" Date: Thu, 1 Sep 2016 14:40:22 +0200 Subject: [PATCH] specfile: change /etc/shells only when (un)installing the package Confirms now to: https://fedoraproject.org/wiki/Packaging:Scriptlets#Shells --- tcsh.spec | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/tcsh.spec b/tcsh.spec index f7401e2..403f04a 100644 --- a/tcsh.spec +++ b/tcsh.spec @@ -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 -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 +# 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 "^/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