%define ver    4.0
%define prefix %{_perfix}
%define snapdate 20040215
%define snapshot stable-%{snapdate}

Name: fml
Version: %{ver}_stable_%{snapdate}
Release: 2%{?_dist_release}
License: GPL
URL: http://www.fml.org/
Source: ftp://ftp.fml.org/pub/fml/stable/%{name}-%{ver}-%{snapshot}.tar.gz
Source1: fml-readme.vine
Patch1: fml-aliases.patch
Patch2: fml-noMailAddress.patch
Group: System Environment/Daemons
Summary: mailing list server and utility package
Summary(ja): メーリングリストサーバとユーティリティ
Requires: perl >= 5.0
BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildPrereq: expect
BuildPrereq: sed
AutoReqProv: 0

Vendor:       Project Vine
Distribution: Vine Linux

%description 
FML is a package of mailing list server and utility programs. It
consists of perl scripts. It has been developed, tested and advanced
in Japan from 1993 to 2001.

%description -l ja
fml はメーリングリスト(以下 ML)を作るためのパッケージです。perl を使っ
て書かれています。fml は、配送とコマンドメールを処理するプログラムを中
核に、多くのプログラムから構成されます。

fml のセットアップやカスタマイズは makefml というプログラムにより、メ
ニューで対話的に行うこともできます。fml 4.0 からは CGI から makefml 
の代表的な機能(登録、削除、メニューによる ML のカスタマイズ)を使う仕組
みもあります。

fml 4.0 の(目に見える)主な新機能は CGI インターフェイス、データベース
アクセス(リレーショナルデータベース、LDAP)などです。
見えない変化としては初期化コードなどです。

fml のデザインの根幹をなす思想は
『趣味やコンピュータ環境は人それぞれであり、それを尊重すること』です。
そのため、様々なカスタマイズをする自由度があります。

%prep
%setup -q -n %{name}-%{ver}-%{snapshot}
%patch1 -p0 -b .aliases
%patch2 -p0 -b .noMailAddress

%build

%install
rm -rf $RPM_BUILD_ROOT

mkdir -p $RPM_BUILD_ROOT/var/
mkdir -p $RPM_BUILD_ROOT/home/fml
mkdir -p $RPM_BUILD_ROOT/home/fml/doc/man
mkdir -p $RPM_BUILD_ROOT/home/fml/sbin

cp %{SOURCE1} $RPM_BUILD_ROOT/home/fml/README-vine

if [ -f fmlmake ]; then rm -f fmlmake ; fi

cat <<-EOF >> ./fmlmake
	set timeout 60
	
	spawn perl ./makefml install
	
	expect "personal"
	send "personal\n"
	expect "DOMAIN NAME"
	send "domainname\n"
	expect "FQDN"
	send "hostname\n"
	expect "EXEC FILES DIRECTORY"
	send "$RPM_BUILD_ROOT/home/fml\n"
	expect "TOP LEVEL ML DIRECTORY"
	send "$RPM_BUILD_ROOT/var/spool/ml\n"
	expect "Language"
	# send "English\n"
	send "Japanese\n"
	expect "TimeZone"
	send "\n"
	expect "Install"
	send "y\n"

	interact
EOF

/usr/bin/expect ./fmlmake

( cd $RPM_BUILD_ROOT/home/fml/doc/man
	sed -e 's/\/var\/tmp\/%{name}-%{version}-root//g' fml.8 > fml.8.$$
        mv fml.8.$$ fml.8
	sed -e 's/\/var\/tmp\/%{name}-%{version}-root//g' makefml.1 > makefml.1.$$
        mv makefml.1.$$ makefml.1

  cd $RPM_BUILD_ROOT/home/fml/sbin/
	sed -e 's/\/var\/tmp\/%{name}-%{version}-root//g' makefml > makefml.$$
        mv makefml.$$ makefml
	chmod 755 makefml
  cd $RPM_BUILD_ROOT/home/fml/.fml 
        sed -e 's/\/var\/tmp\/%{name}-%{version}-root//g' system > system.$$ 
        mv system.$$ system

  cd ..
	rm Configurations
	ln -sf .fml Configurations
	sed -e 's/\/var\/tmp\/%{name}-%{version}-root//g' makefml > makefml.$$
	mv makefml.$$ makefml
	chmod 755 makefml
)

pushd %{buildroot}
for i in `grep -irl %{buildroot} *`
do
	perl -pi -e 's@%{buildroot}@@g' $i
done

%clean
rm -rf $RPM_BUILD_ROOT

%pre
/usr/sbin/groupadd -r fml 
/usr/sbin/useradd -r -g fml fml
exit 0 


%post
FQDN=`hostname`
DOMAIN=`hostname -d`
cd /home/fml/.fml
sed -e "s/hostname/$FQDN/g; s/domainname/$DOMAIN/g" system > system.$$
mv system.$$ system
cd /home/fml
for f in .fml/cgi.conf www/conf/cgi.cf ;
do
  sed -e 's#sendmail#postfix#g; s#/var/tmp/%{name}-%{version}-root##g' $f > $f.$$
  mv $f.$$ $f
done
find www -name \*.cgi -exec sh -c \
  "sed -e 's#/var/tmp/%{name}-%{version}-root##g' {} > {}.$$ ; 
   mv {}.$$ {} ; 
   chown fml.fml {} ;
   chmod +x {} " \;

echo "!!!!!!! CAUTION !!!!!!!"
echo "Be sure to read /home/fml/README-vine."
echo "And the /home/fml/.fml/system is set as follows:"
echo "	FQDN=$FQDN"
echo "	DOMAIN=$DOMAIN"
echo "Please confirm the parameters and edit if you need."

#%postun
#/usr/sbin/userdel fml 

%files
%defattr(-,fml,fml)
/var/spool/ml
/home/fml

%changelog
* Fri May 01 2009 KOBAYASHI Taizo <tkoba@vinelinux.org> 4.0-2
- added aliases and noMailAddress patches

* Thu Sep 25 2008 Shu KONNO <owa@bg.wakwak.com> 4.0-1vl5
- applied new versioning policy, spec in utf-8

* Fri Jul  1 2005 HOTTA Michihide <hotta@net-newbie.com> 4.0-0vl2
- upstream release
- fix config settings under /home/fml

* Sun Apr 20 2003 KOBAYASHI R. Taizo <tkoba@vinelinux.org> 4.0-0vl1
- modified for VineLinux
- update 4.0 release stable-20030419 version

* Fri May 11 2001 YAMAGUCHI Kenji <yamk@kondara.org>
- (fml-4.0_stable_20010509-2k)
- update 4.0 release stable-2001509 version

* Mon Apr 16 2001 YAMAGUCHI Kenji <yamk@kondara.org>
- (fml-4.0_stable_20010410-2k)
- update 4.0 release stable-20010410 version
- append "-r" option to groupadd, useradd

* Fri Apr  6 2001 YAMAGUCHI Kenji <yamk@kondara.org>
- (fml-4.0_stable_20010405-3k)
- update 4.0 release stable-20010405 version

* Sun Apr  1 2001 YAMAGUCHI Kenji <yamk@kondara.org>
- (fml-4.0_stable_20010325-3k)
- update 4.0 release stable-20010325 version
- /var/tmp to %{_tmppath}
- change Source URL.

* Sun Jan 04 2001 YAMAGUCHI Kenji <yamk@kondara.org>
- (fml-4.0_stable_20010202-3k)
- update 4.0 release stable-20010202 version

* Tue Nov 05 2000 Kenji Yamaguchi <yamk@kondara.org>
  [fml-3.0.1_stable_20001027-1k]
- update 3.0.1 release stable-20001027 version

* Tue Aug 15 2000 Kenji Yamaguchi <yamk@kondara.org>
  [fml-3.0.1_stable_20000807-1k]
- update 3.0.1 release stable-20000807 version

* Tue Aug  1 2000 Kenji Yamaguchi <yamk@kondara.org>
  [fml-3.0.1_stable_20000729-1k]
- update 3.0.1 release stable-20000729 version

* Sun Jul 10 2000 Kenji Yamaguchi <yamk@kondara.org>
  [fml-3.0.1_stable_20000628-1k]
- update 3.0.1 release stable-20000628 version
- Fixed Source URL.

* Mon Jun 12 2000 Kenji Yamaguchi <yamk@kondara.org>
- 3.0.1 release stable-20000510 version
- remove source1 "fmlmake". That script is here-document.
- _ja is japanese setup

* Sun Jun 11 2000 Kenji Yamaguchi <yamk@kondara.org>
- 3.0.1 release version

* Sun Mar 12 2000 AYUHANA Tomonori <l@kondara.org>
- SPEC fixed ( Group )

* Mon Nov 8 1999 Toru Hoshina <t@kondara.org>
- be a NoSrc :-P

* Wed Oct 20 1999 Motonobu Ichimura <famao@kondara.org>
- added AutoReqProv 

* Sat Oct 16 1999 Motonobu Ichimura <famao@kondara.org>
- move BuildRoot from /var to /var/tmp and added some changes

* Thu Oct 14 1999 Motonobu Ichimura <famao@kondara.org>
- first release

