Name:             tcsh
Version:          6.24.07
Release:          1
Summary:          C shell with file name completion and command line editing
License:          BSD
URL:              http://www.tcsh.org/
Source0:          http://ftp.funet.fi/pub/mirrors/ftp.astron.com/pub/%{name}/old/%{name}-%{version}.tar.gz

BuildRequires:    gettext-devel ncurses-devel autoconf gcc
Requires(post):   coreutils grep
Requires(postun): sed
Provides:         /bin/csh /bin/tcsh
Provides:         csh = %{version}

Patch0: fix-testcase-fail-if-noroot.patch
Patch1: fix-nice-case-fail-if-noroot.patch

%description
Tcsh is an enhanced but completely compatible version of the Berkeley
C-Shell, with the addition of a command line editor, command and file
name completion, listing, etc., and a bunch of small additions to the
shell itself.

%package help
Summary: help document for tcsh
BuildArch: noarch

%description help
help document for tcsh.

%prep
%autosetup -p1

%build
%configure
%make_build all

%install
%make_install
gzip $RPM_BUILD_ROOT%{_mandir}/man1/tcsh.1
rm -f          $RPM_BUILD_ROOT%{_bindir}/tcsh.old
ln -sf tcsh    $RPM_BUILD_ROOT%{_bindir}/csh
ln -sf tcsh.1.gz  $RPM_BUILD_ROOT%{_mandir}/man1/csh.1.gz

localedir="$RPM_BUILD_ROOT%{_datadir}/locale";
for lang in $(ls $localedir); do
    if [ -d $localedir/$lang ]; then
        dir="$localedir/$lang/LC_MESSAGES"
        if [[ -f "$dir/tcsh.cat" ]]; then
            mv $dir/tcsh.cat $dir/tcsh
            echo "%lang($lang) %{_datadir}/locale/$lang/LC_MESSAGES/tcsh"
        fi
    fi
done > %{name}.lang

%check
%make_build check

%pre

%preun

%post
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 [[ "$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

%files -f %{name}.lang
%defattr(-,root,root)
%doc Copyright FAQ Fixes README.md complete.tcsh
%{_bindir}/tcsh
%{_bindir}/csh

%files help
%defattr(-,root,root)
%{_mandir}/man1/*.1*


%changelog
* Sun Jan 29 2023 renhongxun<renhongxun@h-partners.com> - 6.24.07-1
- upgrade version to 6.24.07

* Mon Nov 21 2022 wangjiang <wangjiang37@h-partners.com> - 6.23.00-3
- modify Source0

* Tue Nov 01 2022 wangjiang <wangjiang37@h-partners.com> - 6.23.00-2
- Rebuild for next release

* Sat Nov 13 2021 shixuantong<shixuantong@huawei.com> - 6.23.00-1
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:update version to 6.23.00

* Thu Jul 22 2021 shixuantong<shixuantong@huawei.com> - 6.22.03-3
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:remove gdb from BuildRequires

* Sat Jun 12 2021 shixuantong<shixuantong@huawei> - 6.22.03-2
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:add gcc to BuildRequires

* Wed Jan 27 2021 fuanan <fuanan3@huawei.com> - 6.22.03-1
- Update to version 6.22.03

* Wed Dec 9 2020 zoulin <zoulin13@huawei.com> - 6.22.02-2
- Type: enhancement
- ID: NA
- SUG: NA
- DESC: Revise Source0

* Tue Aug 4 2020 yangzhuangzhuang <yangzhuangzhuang1@huawei.com> - 6.22.02-1
- Type: enhancement
- ID: NA
- SUG: NA
- DESC: update version to 6.22.02

* Mon Jun 29 2020 chenditang <chenditang1@huawei.com> - 6.21.00-6
- Type: enhancement
- ID: NA
- SUG: NA
- DESC: fix nice case fail if noroot

* Sat Mar 21 2020 openEuler Buildteam <buildteam@openeuler.org> - 6.21.00-5
- Type: enhancement
- ID: NA
- SUG: NA
- DESC: fix testcase fail if noroot

* Sat Mar 21 2020 openEuler Buildteam <buildteam@openeuler.org> - 6.21.00-4
- Type: enhancement
- ID: NA
- SUG: NA
- DESC: add build requires of gdb

* Wed Jan 8 2020 openEuler Buildteam <buildteam@openeuler.org> - 6.21.00-3 
- Type: enhancement
- ID: NA
- SUG: NA
- DESC: revise source0

* Wed Dec 18 2019 jiangchuangang <jiangchuangang@huawei.com> - 6.21.00-2
- Type:enhancement
- ID:NA
- SUG:restart
- DESC:Synchronize patches

* Wed Sep 04 2019 Huiming Xue <xiehuiming@huawei.com> - 6.21.00.1
- modify spec file

* Tue Sep 03 2019 Huiming Xue <xiehuiming@huawei.com> - 6.20.00.11
- Package init
