From Fedora Project Wiki
mNo edit summary
m (Finalization for review.)
Line 6: Line 6:
= How to handle new shells in Fedora packages =
= How to handle new shells in Fedora packages =
As this file can be edited by any people as default, we need to first determine if relevant lines are already existed.
As this file can be edited by any people as default, we need to first determine if relevant lines are already existed.
If existed already, then just echo relevant binary path to the file. Thus, here is an example of package "foo":
If existed already, then just echo relevant binary path to the file. Thus, here is an example of package with shell "foo" underneath /usr/bin:


<code>
<code>
%post
%post
if [ ! -f %{_sysconfdir}/shells ] ; then
if [ "$1" = 1 ]; then
    echo "%{_bindir}/foo" > %{_sysconfdir}/shells
    if [ ! -f %{_sysconfdir}/shells ] ; then
else
        echo "%{_bindir}/foo" > %{_sysconfdir}/shells
  else
     grep -q "^%{_bindir}/foo$" %{_sysconfdir}/shells || echo "%{_bindir}/foo" >> %{_sysconfdir}/shells
     grep -q "^%{_bindir}/foo$" %{_sysconfdir}/shells || echo "%{_bindir}/foo" >> %{_sysconfdir}/shells
fi
fi


%postun
%postun
if [ $1 -eq 0 ] && [ -f %{_sysconfdir}/shells ]; then
if [ "$1" = 0 ] && [ -f %{_sysconfdir}/shells ] ; then
     sed -i '\!^%{_bindir}/foo$!d' %{_sysconfdir}/shells
     sed -i '\!^%{_bindir}/foo$!d' %{_sysconfdir}/shells
fi
fi

Revision as of 06:05, 20 January 2014

Preamble

/etc/shells is a text file which controls system login shell of users. It contains a set of valid shells which can be used in the system.

See: SHELLS(5)

How to handle new shells in Fedora packages

As this file can be edited by any people as default, we need to first determine if relevant lines are already existed. If existed already, then just echo relevant binary path to the file. Thus, here is an example of package with shell "foo" underneath /usr/bin:

%post if [ "$1" = 1 ]; then

   if [ ! -f %{_sysconfdir}/shells ] ; then
       echo "%{_bindir}/foo" > %{_sysconfdir}/shells
 else
   grep -q "^%{_bindir}/foo$" %{_sysconfdir}/shells || echo "%{_bindir}/foo" >> %{_sysconfdir}/shells

fi

%postun if [ "$1" = 0 ] && [ -f %{_sysconfdir}/shells ] ; then

   sed -i '\!^%{_bindir}/foo$!d' %{_sysconfdir}/shells

fi