From Fedora Project Wiki

< User:Cicku‎ | Drafts

Revision as of 07:27, 20 February 2014 by Toshio (talk | contribs) (Fix up grammar. Because of UsrMove, add both %{_bindir} and /bin/ paths)

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: man SHELLS(5)

How to handle new shells in Fedora packages

As this file can be edited by sysadmins, we need to first determine if relevant lines are already in the file. If they don't already exist then we just need to echo the shell's binary path to the file. Since Fedora 17 and later make /bin a symlink to /usr/bin we need to place both paths into the /etc/shells file. Here is an example of the scriptlet to package with shell named "foo":

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

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