#! /bin/sh
# -i suppresses install, -t suppresses stdio test
# options are seen in first argument only, i.e. use -ti not -t -i
umask 002
set -x
: setting up for substitutions
cat >nsubstitutions <<'!'
# master substitutions file
#
# where the programs live (see also NEWSCONFIG)
NEWSBIN		/usr/local/newsbin
# where the control files live
NEWSCTL		/usr/local/lib/news
# where the articles live
NEWSARTS	/var/spool/news
# what PATH should be used for finding normal programs
# (things not in NEWSBIN, that is)
NEWSPATH	/bin:/usr/bin:/usr/local/bin
# the umask under which files should be created
NEWSUMASK	002
# who to send mail to when there is trouble
NEWSMASTER	usenet
# configuration file that lets shell files pick up all of this
NEWSCONFIG	/usr/local/lib/news/bin/config
!
if test -r substitutions && cmp -s nsubstitutions substitutions
then
	rm nsubstitutions
else
	mv nsubstitutions substitutions
fi
: done
: building headers
cd ..
if test ! -d include
then
	mkdir include include/sys
fi
cd h
rm -f nnewshsed
echo "/FASTSTRCHR.*qqq/s;^;/* ;" >>nnewshsed
echo "/SMALLMEM.*qqq/s;^;/* ;" >>nnewshsed
if test -f newshsed && cmp -s nnewshsed newshsed
then
	rm -f nnewshsed
else
	mv nnewshsed newshsed
fi
make all COPTS='-O' DBM= || exit 1
cd ../hfake
sed -e '/NEEDED =/s~.*~NEEDED = ~' Makefile >M.$$
mv -f M.$$ Makefile
make all COPTS='-O' DBM= || exit 1
: done
: making substitutions...
cd ../conf
make substs COPTS='-O' DBM= || exit 1
: done
: making library...
touch ../ranlibed ; sleep 2
for dir in libbsd42 libbig libc libcnews  dbz
do
	cd ../$dir
	make u COPTS='-O' DBM= || exit 1
done
cd ../libfake
sed -e '/NEEDED =/s/.*/NEEDED = /' Makefile >M.$$
mv -f M.$$ Makefile
make u COPTS='-O' DBM= || exit 1
cd ../conf
make ../ranlibed COPTS='-O' DBM= || exit 1
: library done
: making spacefor, queuelen, etc....
cd ../conf
rm -f spacefor queuelen hostname setnewsids
make sf.bsd COPTS='-O' DBM= || exit 1
cp sf.bsd spacefor
make queuelen.hdb COPTS='-O' DBM= || exit 1
cp queuelen.hdb queuelen
: done
: building programs
for dir in conf batch dbz expire input relay misc explode inject rna
do
	cd ../$dir
	make all COPTS='-O' DBM= || exit 1
done
: done
: building prototype control files
cd ../conf
rm -f active errlog history history.pag history.dir localgroups log mailname mailpaths organization postdefltdist postdefltgroup replyusepath server sys whoami rnews.stall rnews.immed readnews.ctl
cp config.proto config
echo 'hub.dn.com.au' >mailname
cat <<'!' >organization
Design Networks
!
echo 'aus' >>postdefltdist
echo 'defsub	aus.general' >readnews.ctl
echo 'mustsub	aus.general' >>readnews.ctl
echo 'hub' >whoami
echo 'general 0000000000 0000000001 y' >active
echo 'news.announce.newusers 0000000000 0000000001 y' >>active
echo 'control 0000000000 0000000001 y' >>active
echo 'junk 0000000000 0000000001 y' >>active
>errlog
>history
>history.pag
>history.dir
echo 'general	general local news' >localgroups
>log
echo 'all	uunet!%s' >mailpaths
cp sys.proto sys
cd ../expire
make explists COPTS='-O' DBM= && cp explist.no explist
cd ../conf
cat >cron <<'!'
0,15,30,45 *	1-31 *	0-6	su news -c '/usr/local/newsbin/input/newsrun'
30 8	1-31 *	1-5	su news -c '/usr/local/newsbin/input/newsrunning off'
00 17	1-31 *	1-5	su news -c '/usr/local/newsbin/input/newsrunning on'
40 *	1-31 *	0-6	su news -c '/usr/local/newsbin/batch/sendbatches'
59 0	1-31 *	0-6	su news -c '/usr/local/newsbin/expire/doexpire '
10 8	1-31 *	0-6	su news -c '/usr/local/newsbin/maint/newsdaily'
00 5,13,21	1-31 *	0-6	su news -c '/usr/local/newsbin/maint/newswatch | mail usenet'
!
echo 'su news -c /usr/local/newsbin/maint/newsboot' >rc
: done
case "$1" in
-*i*)	exit 0	;;
esac
: installing programs
for dir in conf batch dbz expire input relay misc explode inject rna
do
	cd ../$dir
	make bininstall BIN=/usr/local/bin RBIN=/bin COPTS='-O' DBM= || exit 1
done
: done
: installing manual pages
cd ../man
cp checknews.1 /usr/local/man/man1/checknews.1
cp injnews.1 /usr/local/man/man1/injnews.1
cp postnews.1 /usr/local/man/man1/postnews.1
cp active.times.5 /usr/local/man/man5/active.times.5
cp news.5 /usr/local/man/man5/news.5
cp newsctl.5 /usr/local/man/man5/newsctl.5
cp newsdb.5 /usr/local/man/man5/newsdb.5
cp newssys.5 /usr/local/man/man5/newssys.5
cp expire.8 /usr/local/man/man8/expire.8
cp explode.8 /usr/local/man/man8/explode.8
cp newsaux.8 /usr/local/man/man8/newsaux.8
cp newsbatch.8 /usr/local/man/man8/newsbatch.8
cp newsmail.8 /usr/local/man/man8/newsmail.8
cp newsmaint.8 /usr/local/man/man8/newsmaint.8
cp relaynews.8 /usr/local/man/man8/relaynews.8
cp rnews.8 /usr/local/man/man8/rnews.8
: done
