#! /bin/sh

# functions and headers we are prepared to fake
mightfake='fsync getopt index memcpy memcmp memchr memset mkdir
	putenv rindex strchr strrchr strpbrk strspn strcspn strtok symlink'
mightfakehdrs='stdlib.h string.h'

# directories in which to do makes
# batch must precede input; relay must precede misc
pgmdirs='conf batch expire input relay misc rna'

# control files built in conf
ctlf="active allowed errlog history history.pag history.dir localgroups"
ctlf="$ctlf log mailname mailpaths organization postdefltdist postdefltgroup"
ctlf="$ctlf replyusepath server sys whoami"

echo 'This interactive command will build shell files named doit.root,'
echo 'doit.bin, doit.news, and again.root to do all the work.  It will not'
echo 'actually do anything itself, so feel free to abort and start again.'
echo
echo 'You probably need your system manuals handy.'
echo
echo 'When a question is asked in the form "How are you [okay]? ", the'
echo 'answer in brackets is what you will get if you just hit RETURN.'

chmod +x query			# just in case
if test " `./query hi | wc -c`" -ne 2
then
	echo 'The "query" utility that this command needs does not seem to'
	echo 'be working properly.  It is supposed to work like "echo"'
	echo 'except not produce a newline at the end.  You will have to fix'
	echo 'it (it is a shell file).  (Most versions of "echo" have a way'
	echo 'to suppress the newline, but unfortunately there are at least'
	echo 'two different incompatible ways.)'
	exit 1
fi

echo
echo 'C News wants to keep most of its files under a uid which preferably'
echo 'should be all its own.  Its programs, however, can and probably should'
echo 'be owned by another user, typically the same one who owns most of the'
echo 'rest of the system.'
./query 'What user id should be used for news files [news]? '
read newsuid
case "$newsuid" in
'')	newsuid=news	;;
esac
./query 'What group id should be used for news files [news]? '
read newsgid
case "$newsgid" in
'')	newsgid=news	;;
esac
./query 'What user id should be used for news programs [bin]? '
read binuid
case "$binuid" in
'')	binuid=bin	;;
esac
./query 'What group id should be used for news programs [bin]? '
read bingid
case "$bingid" in
'')	bingid=bin	;;
esac

answer=
if test -d /var -a -d /usr/share
then
	echo
	echo 'It would appear that your system is among the victims of the'
	echo '4.4BSD / SVR4 directory reorganization, with (e.g.) shared'
	./query 'data in /usr/share.  Is this correct [yes]? '
	read answer
	case "$answer" in
	y*|Y*|'')	answer=y	;;
	esac
fi
if test " $answer" = " y"
then
	echo 'This will affect where C News directories go.  We recommend'
	echo 'making the directories wherever they have to go and then making'
	echo 'symbolic links to them under the standard names that are used'
	echo 'as defaults in the following questions.  Should such links'
	./query 'be made [yes]? '
	read makelinks
	case "$makelinks" in
	y*|Y*|'')	makelinks=y	;;
	esac
	echo 'Our 4.4ish friends suggest putting articles in /var/spool/news'
	echo 'and control files in /usr/share/news, with programs left where'
	echo 'they are in /usr/lib/newsbin.'
fi

needsubst=
echo
echo 'C News lives primarily under three directories:  one for articles (and'
echo 'incoming and outgoing spooling), one for control files, and one for'
echo 'programs.'
./query 'Where should articles live [/usr/spool/news]? '
read newsarts
case "$newsarts" in
'')	newsarts=/usr/spool/news	;;
*)	needsubst=y	;;
esac
./query 'Where should control files live [/usr/lib/news]? '
read newsctl
case "$newsctl" in
'')	newsctl=/usr/lib/news	;;
*)	needsubst=y	;;
esac
./query 'Where should programs live [/usr/lib/newsbin]? '
read newsbin
case "$newsbin" in
'')	newsbin=/usr/lib/newsbin	;;
*)	needsubst=y	;;
esac
if test " $makelinks" = " y"
then
	realarts="$newsarts"
	realctl="$newsctl"
	realbin="$newsbin"
	newsarts="/usr/spool/news"
	newsctl="/usr/lib/news"
	newsbin="/usr/lib/newsbin"
fi

echo
echo 'C News by default assumes that all normal Unix programs can be found'
echo 'in /bin or /usr/bin.  This is naive, especially on Berkeley-derived'
echo 'systems where some standard programs inexplicably moved to /usr/ucb.'
newspath='/bin:/usr/bin'
if test '(' ! -f /bin/wc -a ! -f /usr/bin/wc ')' -o \
			'(' ! -f /bin/hostname -a ! -f /usr/bin/hostname -a \
						-f /usr/ucb/hostname ')'
then
	echo 'It would appear that some standard programs live in /usr/ucb'
	./query 'on your system.  Is that right [yes]? '
	read ucb
else
	echo 'It would appear that /usr/ucb does not exist or is not needed'
	./query 'for normal operation on your system.  Is that right [yes]? '
	read ucb
	case "$ucb" in
	y*|Y*|'')	ucb=no	;;
	n*|N*)		ucb=yes	;;
	esac
fi
case "$ucb" in
y*|Y*|'')	./query 'Should /usr/ucb go before or after /bin and /usr/bin [after]
 '
		read answer
		case "$answer" in
		a*|A*|'')	newspath="$newspath:/usr/ucb"	;;
		*)		newspath="/usr/ucb:$newspath"	;;
		esac
		needsubst=y
		;;
esac
while true
do
	echo 'Is there any other directory which should be searched to find'
	./query 'standard programs on your system [no]? '
	read answer
	case "$answer" in
	n*|N*|'')	break	;;
	*)		needsubst=y	;;
	esac
	./query 'What is the full name of the directory? '
	read dir
	./query 'Should it go before or after the others [after]? '
	read answer
	case "$answer" in
	a*|A*|'')	newspath="$newspath:$dir"	;;
	*)		newspath="$dir:$newspath"	;;
	esac
done

echo
echo 'C News normally uses a umask of 002, turning off only the others-write'
echo 'bit in the permissions of files used.  (The correspondence between bits'
echo 'and number is:  rwx = 421, so turning off group-write bits and all'
echo 'others-access bits would be a mask of 027, for example.)  Usually'
echo 'a umask of 002 or 022 is appropriate.'
./query 'What umask should C News use [002]? '
read newsumask
case "$newsumask" in
'')	newsumask=002	;;
*)	needsubst=y	;;
esac

echo
echo 'C News wants to mail some forms of trouble reports to an administrator.'
echo 'You probably want to make this a system mailbox, rather than that of a'
echo "specific user, so you won't have to change the software when you get a"
echo 'new administrator.'
./query 'Where should C News mail trouble reports [usenet]? '
read newsmaster
case "$newsmaster" in
'')	newsmaster=usenet	;;
*)	needsubst=y	;;
esac

echo
echo 'The shell files that are everywhere in C News want to pick up their'
echo 'configuration parameters (mostly, the last few questions you have'
echo 'answered) from a file at a known location; this is very hard to avoid'
echo 'unless you play tricks with environment variables (see documentation).'
echo 'Where should the shell configuration file be'
./query "located [$newsctl/bin/config]? "
read newsconfig
case "$newsconfig" in
'')	newsconfig=$newsctl/bin/config	;;
*)	needsubst=y	;;
esac

echo
./query 'What is the full pathname of the chown command [/etc/chown]? '
read chown
case "$chown" in
'')	chown=/etc/chown	;;
esac
echo "Can I say '$chown $newsuid.$newsgid file' to change both the user id"
./query 'and group id of a file [yes]? '
read chboth
case "$chboth" in
y*|Y*|'')	chboth=y	;;
esac
if test " $chboth" != " y"
then
	./query 'Is there a chgrp command to change the group of a file [yes]? '
	read chgrp
	case "$chgrp" in
	n*|N*)	echo 'You will need to edit doit.root by hand before running it.'
		echo "It will assume that 'chown $newsuid.$newsgid' works."
		chboth=y
		;;
	*)	./query 'What is the full pathname of the chgrp command [/etc/chgrp]? '
		read chgrp
		case "$chgrp" in
		'')	chgrp=/etc/chgrp	;;
		esac
		;;
	esac
fi

echo
echo 'building doit.root...'
>doit.root
if test ! -w doit.root
then
	echo 'It appears that I cannot create doit.root.  Aborting.'
	exit 1
fi
(
	echo "umask $newsumask"
	echo 'set -x'
	echo ": making directories..."
	if test " $makelinks" = " y"
	then
		echo "mkdir $realarts $realctl $realbin"
		if test " $realarts" != " $newsarts"
		then
			echo "ln -s $realarts $newsarts"
		fi
		if test " $realctl" != " $newsctl"
		then
			echo "ln -s $realctl $newsctl"
		fi
		if test " $realbin" != " $newsbin"
		then
			echo "ln -s $realbin $newsbin"
		fi
	fi
	n="$newsarts $newsarts/in.coming $newsarts/in.coming/bad"
	n="$n $newsarts/out.going $newsctl $newsctl/bin"
	b="$newsbin"
	echo "for d in $n $b"
	echo "do"
	echo "	if test ! -d \$d"
	echo "	then"
	echo "		mkdir \$d"
	echo "	fi"
	echo "done"
	if test " $chboth" = " y"
	then
		echo "$chown $newsuid.$newsgid $n"
		echo "$chown $binuid.$bingid $b"
	else
		echo "$chown $newsuid $n"
		echo "$chgrp $newsgid $n"
		echo "$chown $binuid $b"
		echo "$chgrp $bingid $b"
	fi
	echo ": done"
) >>doit.root
echo 'done'

echo
echo 'C News has libraries for several kinds of Unix:'
echo '	bsd42	4.2BSD and successors'
echo '	usg	AT&T System V'
echo '	v7	Version 7 (4.1BSD is pretty close, ditto Xenix)'
echo '	v8	Version 8, aka Eighth Edition'
while true
do
	./query 'Which best describes your system [v7]? '
	read unixkind
	if test " $unixkind" = " "
	then
		unixkind=v7
	fi
	if test -d ../lib$unixkind
	then
		break
	fi
	echo 'Sorry, no such library is supplied.'
done

echo
echo 'C News has libraries for small address spaces (16 bits) and big'
echo 'ones (preferably 32 bits, but anything rather bigger than 16).'
while true
do
	./query 'Which best describes your system [big]? '
	read addrsize
	if test " $addrsize" = " "
	then
		addrsize=big
	fi
	if test -d ../lib$addrsize
	then
		break
	fi
	echo 'Sorry, no such library is supplied.'
done

echo
echo 'Systems vary in whether certain library functions and system calls'
echo 'are present.  C News contains reasonably-portable versions of the'
echo 'possibly-missing library functions, and fake versions of the'
echo 'possibly-missing system calls, but it needs to know which are missing.'
fake=
for fn in $mightfake
do
	./query "Does your system have  $fn() [yes]? "
	read answer
	case "$answer" in
	y*|Y*|'')	;;
	*)	fake="$fake $fn.o"	;;
	esac
done
./query "Does your system have a library function ldiv() as in ANSI C? [yes]? "
read answer
case "$answer" in
y*|Y*|'')	;;
*)	fake="$fake ldiv.o"	;;
esac
./query 'Does your system have the "dbm" library [yes]? '
read answer
case "$answer" in
y*|Y*|'')	./query 'What is the compile option needed to get it [-ldbm]? '
		read answer
		case "$answer" in
		'')	answer=-ldbm	;;
		esac
		dbm="DBM=$answer"
		;;
*)	fake="$fake dbm.o"
	dbm='DBM='
	;;
esac

echo
echo 'Many systems, notably older ones, have implementations of the Standard'
echo 'I/O library ("stdio") in which fgets, fputs, fread, and fwrite, although'
echo 'correct, are quite slow.  We supply versions of these functions which'
echo 'are faster than those in any stdio we know; they are compatible with'
echo 'most AT&T-derived stdios.  If they work on your system, they are a'
echo 'major performance win for C News.  There is a simple compatibility'
echo 'check run after the library is built.  The only system we know of'
echo 'where the test works but the functions do not is SunOS 4.0.'
./query 'Do you want to use our fast stdio library [yes]? '
read libstdio
case "$libstdio" in
y*|Y*|'')	libstdio=libstdio	;;
*)		libstdio=		;;
esac

if test " $dbm" != " DBM="
then
	echo
	echo 'Does the store() function in your dbm library return a'
	./query 'value (some old ones did not) [yes]? '
	read storeval
	case "$storeval" in
	y*|Y*|'')	storeval=y	;;
	esac
else
	storeval=y
fi

found=
for f in $fake dummy
do
	if test " $f" = " index.o"
	then
		found=y
	fi
done
if test " $found" = " "
then
	echo
	echo 'A well-tuned index() function customized to a particular machine'
	echo 'is usually faster than portable C.  Is your index() function'
	./query 'indeed fast [yes]? '
	read fastindex
	case "$fastindex" in
	y*|Y*|'')	fastindex=y	;;
	esac
fi

echo
echo 'Modern Unixes can generally use the setuid() system call to set the'
echo 'real and effective user ids to the current effective user id.  In'
echo 'old Unixes, only "root" can change the real user id.  This causes'
echo 'various problems for C News.  C News provides a small program named'
echo '"setnewsids" to run setuserid-root; all it does is change user and'
echo 'group ids and then execute C News "relaynews".  It is needed only in'
echo 'systems that are too old to do setuid(geteuid()).  Relaynews invokes'
echo 'it automatically if needed (and it then invokes relaynews in return).'
./query 'Can this system do setuid(geteuid()) [yes]? '
read sete
case "$sete" in
y*|Y*|'')	sete=y	;;
esac

echo
echo 'Some systems have header files that others lack, and C News'
echo 'is prepared to fake missing ones.'
fakehdrs=
for h in $mightfakehdrs
do
	./query "Does your system have an ANSI-C-conforming <$h> [yes]? "
	read answer
	case "$answer" in
	y*|Y*|'')	;;
	*)	fakehdrs="$fakehdrs ../include/$h"	;;
	esac
done
./query "Does your system have <sys/timeb.h> [yes]? "
read answer
case "$answer" in
n*|N*)	fakehdrs="$fakehdrs ../include/sys/timeb.h"	;;
esac

echo
echo 'Some old systems think sprintf() returns a value of type "char *".'
echo 'The modern standard is that it returns "int".  Does your sprintf()'
./query 'return "char *" [no]? '
read answer
case "$answer" in
n*|N*|'')	;;
*)		echo 'You may have to hand-edit our "libc.h" include file if'
		echo 'your compiler objects to us declaring sprintf() to'
		echo 'return "int".  (This will usually happen only if your'
		echo '<stdio.h> header file declares sprintf() -- some do,'
		echo 'some do not.)  If you do need to edit "libc.h", look'
		echo 'for the definition of "sprvalue".'
		;;
esac

echo
echo 'Very old Unix systems needed the order of object modules in a library'
echo 'chosen very carefully.  V7 introduced "ranlib" which removes the need'
echo 'for this.  Recent System Vs have had the same facility built into "ar"'
echo '(look for "symdef" in the "ar" manual page) so "ranlib" is not needed.'
./query "Does your system have a 'ranlib' command [no]? "
read ranlib
case "$ranlib" in
n*|N*|'')
	./query 'Does your "ar" have a "symdef" feature [yes]? '
	read answer
	case "$answer" in
	n*|N*)	echo 'You have trouble and may need to modify doit.bin before'
		echo 'running it.  It will assume "ranlib" is present.'
		ranlib=y
		;;
	*)	ranlib=
		;;
	esac
	;;
*)	ranlib=y
	;;
esac

echo
echo 'Historically the C compiler is named "cc", but this is not true on'
echo 'some systems, and on others there are several different C compilers.'
./query 'What is the name of the C compiler to be used [cc]? '
read cc
case "$cc" in
'')	cc=	;;
*)	cc="CC=$cc"	;;
esac

echo
echo 'Historically the only normal compilation option needed for most'
echo 'programs is -O, but again compilers, especially newer ones, differ.'
./query "What options should be given to the compiler [-O]? "
read copts
case "$copts" in
'')	copts=	;;
*)	copts="COPTS='$copts'"	;;
esac

echo
./query 'Does your system have a "hostname" command [yes]? '
read hostname
case "$hostname" in
y*|Y*|'')	hostname=y	;;
*)	./query 'Does it have a "uname" command with a "-n" option [yes]? '
	read hostname
	case "$hostname" in
	y*|Y*|'')	hostname=u	;;
	*)		hostname=	;;
	esac
	;;
esac

echo
echo 'C News tries to limit the backlog of news batches spooled up for'
echo 'transmission to a site, to control use of disk space.  To do this,'
echo 'it needs to be able to determine the length of the queue of news'
echo 'batches for a particular site.  This is UUCP-version-dependent.'
echo 'There is a good chance that you will have to customize the "queuelen"'
echo 'program.  C News knows about several versions:'
echo '	hdb	Honey DanBer, aka Basic Networking Utilities'
echo '	sub	old uucp with subdirectories (e.g. /usr/spool/uucp/C.)'
echo "	null	don't run uucp or don't care about queue lengths"
while true
do
	./query 'Which one is most appropriate [hdb]? '
	read uucptype
	case "$uucptype" in
	'')	uucptype=hdb	;;
	sub)	echo 'Beware -- test "queuelen" to make sure it works.'	;;
	esac
	case "$uucptype" in
	hdb|sub|null)	break	;;
	esac
	echo 'Sorry, no such choice is available.'
done

echo
echo 'C News often wants to ask how much disk space is available.  The'
echo 'format of output from the "df" command unfortunately varies a lot.'
echo 'C News knows about several different versions:'
echo '	bsd	4.2BSD and later'
echo '	sysv	most System Vs'
echo '	sgi	Silicon Graphics Iris systems'
echo '	v7	plain old style:  no headers or fluff, just name and number'
echo "	null	don't know or don't care how much space is available"
while true
do
	./query 'Which one is most appropriate [bsd]? '
	read dftype
	case "$dftype" in
	'')	dftype=bsd	;;
	sysv)	echo 'Beware -- test "spacefor" to make sure it works.'
		echo 'System V "df" formats vary widely, indeed wildly.'
		echo '"Consider it standard".  Sure.'
		;;
	esac
	case "$dftype" in
	bsd|sysv|sgi|v7|null)	break	;;
	esac
	echo 'Sorry, no such choice is available.'
done

echo
echo 'Some "df" commands, especially on old systems, must be given the'
echo 'name of a device.  Modern ones can be given any directory name and'
echo 'the system handles the details of figuring out what device is meant.'
./query 'Does your "df" accept a directory name as an argument [yes]? '
read answer
case "$answer" in
n*|N*)	echo 'You are going to have to customize "spacefor" for your system.'
	echo 'It will be generated assuming that directory names do work.'
	;;
esac

echo
./query 'Are you planning to use expire to archive news on disk [no]? '
read answer
case "$answer" in
y*|Y*)	echo 'You probably want to customize the "archive" entry in'
	echo '"spacefor" so it knows where your archiving is done and how'
	echo 'much space you want free there.'
	;;
esac

echo
./query 'Are you particularly short of disk space [no]? '
read answer
case "$answer" in
y*|Y*)	echo 'You may want to reconsider whether you really want to get'
	echo 'news, unless you are getting only a very small set of groups.'
	echo 'In any case, you definitely want to inspect "spacefor" and'
	echo 'change some of its thresholds for free space.'
	;;
*)	echo 'You may want to inspect "spacefor" to make sure its defaults'
	echo 'for things like desired free space are appropriate for your'
	echo 'system, although the defaults are fairly conservative.'
	;;
esac

echo
echo 'Are you running C News on a group of machines hooked together with'
./query 'NFS, with articles filed on only one "server" machine [no]? '
read answer
server=
case "$answer" in
y*|Y*)	if test " $hostname" = " "
	then
		echo 'With a server but no "hostname" command, you will have'
		echo 'problems and will probably have to tinker by hand to'
		echo 'get a fake "hostname" that does the right thing.  The'
		echo 'generated files will assume you have "hostname".'
		hostname=y
	fi
	if test " $hostname" = " u"
	then
		./query 'What is the "uname -n" name of the server? '
	else
		./query 'What is the "hostname" name of the server? '
	fi
	read server
	;;
esac

echo
echo 'Several programs need to know an overall name for the system news is'
echo 'being run on, where "system" may include multiple machines if they'
echo 'share a common set of control files and articles; this is used in'
echo 'article headers and related places.  For uucp sites, this usually'
echo 'should be the uucp name.  What is the name of the overall system'
./query 'for news purposes? '
read whoami

echo
echo 'The "From:" lines of news postings, on the other hand, should carry'
echo 'a mailing address, which in particular should be a domain address'
echo 'for sites that have one.  What is the mailing-address name of this'
./query "system, preferably a domain address [$whoami.uucp]? "
read mailname
case "$mailname" in
'')	mailname="$whoami.uucp"	;;
esac

echo
echo 'What is the name of the organization, for insertion into articles'
./query 'posted from here? '
read organization

echo
echo 'What user other than root (if any) should be allowed to create'
./query 'new news groups [no such user]? '
read allowed

echo
echo 'Manual pages are normally stored in a tree structure under /usr/man.'
echo 'Local practices vary a great deal, however, and System V has also'
echo 'introduced some bizarre distortions into this once-simple structure.'
./query 'What is the top-level manual-page directory [/usr/man]? '
read manpages
case "$manpages" in
'')	manpages=/usr/man	;;
esac

echo
chaps='1 5 8'
echo 'C News adds manual pages to chapters 1 (programs), 5 (files), and'
echo '8 (administrative programs).  These chapter numbers have changed'
echo 'in some variants of Unix.  Also, originally pages from chapter 5 (for'
echo "example) were stored in $manpages/man5.  This has also changed in"
./query 'some variants.  Has your system made either of these changes [no]? '
read answer
case "$answer" in
y*|Y*)	echo 'You will have to hand-edit the last few lines of doit.bin'
	echo 'to install the manual pages where they belong on your system.'
	;;
esac

echo
echo 'The "rnews" and "cunbatch" commands (which are identical, the latter'
echo 'being purely for backward compatibility with seriously-old systems)'
echo 'have to be installed somewhere where uucp can find them to execute'
echo 'them.  It is not normally necessary for users to be able to run'
echo 'them, so they need not go in the directories searched for normal'
echo 'commands... although uucp often searches only those directories.'
./query 'What directory should "rnews" and "cunbatch" go in [/bin]? '
read rbin
case "$rbin" in
'')	rbin=/bin	;;
esac

echo
echo 'The "inews", "postnews", "readnews", and "checknews" commands should'
echo 'go in one of the directories searched for normal commands, so users'
echo 'can run them without special arrangements.  What directory should'
./query 'these commands go in [/bin]? '
read bin
case "$bin" in
'')	bin=/bin	;;
esac

echo
echo 'For replies to control messages, C News invokes "mail" (typically'
echo '/bin/mail unless you make special arrangements) with either an'
echo 'Internet-style "@" address or a uucp-style "!" address.  Internet'
echo 'style is probably better... if your mailer supports it at all.'
./query 'Will "mail" handle "@" addresses [no]? '
read atok
case "$atok" in
y*|Y*)	atok=y	;;
*)	atok=	;;
esac

echo
echo 'Postnews can supply a default newsgroup, to assist naive users in'
echo 'getting the group right for simple postings.  What should the default'
./query 'newsgroup for postnews be [no default]? '
read postdefltgroup

echo
echo 'Postnews can supply a default distribution, to restrict news to a'
echo 'local area unless the user specifically changes it.  This is probably'
echo 'a good idea.  What should the default distribution for postnews'
./query 'be [world]? '
read postdefltdist

echo
echo 'building doit.bin...'
>doit.bin
if test ! -w doit.bin
then
	echo 'It appears that I cannot create doit.bin.  Aborting.'
	exit 1
fi
(
	echo "umask $newsumask"
	echo "set -x"
	echo ': setting up for substitutions'
	echo "cat >nsubstitutions <<'!'"
	cat <<!
# master substitutions file
#
# where the programs live (see also NEWSCONFIG)
NEWSBIN		$newsbin
# where the control files live
NEWSCTL		$newsctl
# where the articles live
NEWSARTS	$newsarts
# what PATH should be used for finding normal programs
# (things not in NEWSBIN, that is)
NEWSPATH	$newspath
# the umask under which files should be created
NEWSUMASK	$newsumask
# who to send mail to when there is trouble
NEWSMASTER	$newsmaster
# configuration file that lets shell files pick up all of this
NEWSCONFIG	$newsconfig
!
	echo '!'
	echo 'if test -r substitutions && cmp -s nsubstitutions substitutions'
	echo 'then'
	echo '	rm nsubstitutions'
	echo 'else'
	echo '	mv nsubstitutions substitutions'
	echo 'fi'
	echo ': done'
	echo ': building headers'
	echo 'cd ..'
	echo 'if test ! -d include'
	echo 'then'
	echo '	mkdir include include/sys'
	echo 'fi'
	echo 'cd h'
	echo 'rm -f nnewshsed'
	if test " $fastindex" != " y"
	then
		echo 'echo "/FASTINDEX.*qqq/s;^;/* ;" >>nnewshsed'
	fi
	if test " $storeval" = " y"
	then
		echo 'echo "/NOSTOREVAL.*qqq/s;^;/* ;" >>nnewshsed'
	fi
	if test " $addrsize" = " big"
	then
		echo 'echo "/SMALLMEM.*qqq/s;^;/* ;" >>nnewshsed'
	fi
	echo 'if test -f newshsed && cmp -s nnewshsed newshsed'
	echo 'then'
	echo '	rm -f nnewshsed'
	echo 'else'
	echo '	mv nnewshsed newshsed'
	echo 'fi'
	echo 'make all || exit 1'
	echo 'cd ../hfake'
	echo "ed - Makefile <<'!'"
	echo "/NEEDED =/s~.*~NEEDED = $fakehdrs~"
	echo "w"
	echo "!"
	echo "make all || exit 1"
	echo ": done"
	echo ": making substitutions..."
	echo "cd ../conf"
	if test " $needsubst" = " y"
	then
		echo "make substs"
	else
		echo ": make substs		not necessary, defaults used"
	fi
	echo ": done"
	echo ": making spacefor, queuelen, etc...."
	echo "rm -f spacefor queuelen hostname setnewsids"
	echo "make spacefor.$dftype"
	echo "cp spacefor.$dftype spacefor"
	echo "make queuelen.$uucptype"
	echo "cp queuelen.$uucptype queuelen"
	if test " $hostname" = " y"
	then
		echo "# ( echo '#! /bin/sh' ; echo 'echo $whoami' ) >hostname"
	elif test " $hostname" = " u"
	then
		echo "( echo '#! /bin/sh' ; echo 'uname -n' ) >hostname"
	else
		echo "( echo '#! /bin/sh' ; echo 'echo $whoami' ) >hostname"
	fi
	echo ': done'
	echo ': making library...'
	if test " $ranlib" = " y"
	then
		echo "touch ../ranlibed"
		echo "sleep 2"
	fi
	echo "for dir in lib$unixkind lib$addrsize libc libcnews $libstdio"
	echo "do"
	echo "	cd ../\$dir"
	echo "	make u $cc $copts || exit 1"
	echo "done"
	echo "cd ../libfake"
	echo "ed - Makefile <<'!'"
	echo "/NEEDED =/s/.*/NEEDED = $fake/"
	echo "w"
	echo "!"
	echo "make u $cc $copts || exit 1"
	echo "cd ../conf"
	if test " $ranlib" = " y"
	then
		echo "make ../ranlibed"
	fi
	echo ': library done'
	if test " $libstdio" != " "
	then
		echo ': testing libstdio'
		echo 'cd ../libstdio'
		echo "make trials $cc $copts || exit 1"
		echo ': done'
	fi
	echo ': building programs'
	echo 'cd ../conf'
	if test " $sete" != " y"
	then
		echo "make setnewsids NEWSUSER=$newsuid NEWSGROUP=$newsgid $cc $copts"
	fi
	echo "for dir in $pgmdirs"
	echo "do"
	echo "	cd ../\$dir"
	echo "	make all $dbm $cc $copts"
	echo "done"
	echo ": done"
	echo ": building prototype control files"
	echo "cd ../conf"
	echo "rm -f $ctlf"
	echo "cp config.proto config"
	echo "echo '$mailname' >mailname"
	echo "echo '$organization' >organization"
	if test " $allowed" != " "
	then
		echo "echo '$allowed' >allowed"
	fi
	if test " $server" != " "
	then
		echo "echo '$server' >server"
	fi
	if test " $atok" != " y"
	then
		echo echo "'replies must use "!" addresses' >replyusepath"
	fi
	if test " $postdefltdist" != " "
	then
		echo "echo '$postdefltdist' >>postdefltdist"
	fi
	if test " $postdefltgroup" != " "
	then
		echo "echo '$postdefltgroup' >>postdefltgroup"
	fi
	echo "echo '$whoami' >whoami"
	echo "echo 'general 00000 00000 y' >active"
	echo "echo 'news.announce.newusers 00000 00000 y' >>active"
	echo ">errlog"
	echo ">history"
	echo ">history.pag"
	echo ">history.dir"
	echo "echo 'general	general local news' >localgroups"
	echo ">log"
	echo "echo 'all	uunet!%s' >mailpaths"	# crude
	echo "cp sys.proto sys"
	echo "cat >cron <<'!'"
	cat <<!
15 *	1-31 *	0-6	su news -c '$newsbin/input/newsrun'
30 8	1-31 *	1-5	su news -c '$newsbin/input/newsrunning off'
00 17	1-31 *	1-5	su news -c '$newsbin/input/newsrunning on'
40 *	1-31 *	0-6	su news -c '$newsbin/batch/sendbatches'
59 0	1-31 *	0-6	su news -c '$newsbin/expire/doexpire'
45 3	1-31 *	0-6	su news -c '$newsbin/expire/superkludge comp.mail.maps'
10 8	1-31 *	0-6	su news -c '$newsbin/maint/newsdaily'
00 5,13,21	1-31 *	0-6	su news -c '$newsbin/maint/newswatch'
!
	echo "!"
	echo "echo 'su news -c $newsbin/maint/newsboot' >rc"
	echo ": done"
	echo ': installing programs'
	echo "for dir in $pgmdirs"
	echo "do"
	echo "	cd ../\$dir"
	echo "	make bininstall BIN=$bin RBIN=$rbin $dbm"
	echo "done"
	echo ": done"
	echo ': installing manual pages'
	echo 'cd ../man'
	for chap in $chaps
	do
		for f in `ls ../man | egrep "\.$chap\$"`
		do
			echo "cp $f $manpages/man$chap/$f"
		done
	done
	echo ': done'
) >>doit.bin
echo 'done'

echo
echo 'building doit.news...'
>doit.news
if test ! -w doit.news
then
	echo 'It appears that I cannot create doit.news.  Aborting.'
	exit 1
fi
(
	echo "umask $newsumask"
	echo 'set -x'
	echo ': installing programs'
	echo "for dir in $pgmdirs"
	echo "do"
	echo "	cd ../\$dir"
	echo "	make newsinstall BIN=$bin RBIN=$rbin $dbm"
	echo "done"
	echo ": done"
	echo ": installing control files"
	echo "cd ../conf"
	echo "for f in $ctlf"
	echo "do"
	echo "	if test -r $newsctl/\$f"
	echo "	then"
	echo "		echo \"$newsctl/\$f already exists; left unchanged\""
	echo "	elif test ! -r \$f"
	echo "	then"
	echo "		: \"\$f\" not wanted"
	echo "	else"
	echo "		cp \$f $newsctl/\$f"
	echo "	fi"
	echo "done"
	echo "if test -r $newsconfig"
	echo "then"
	echo "	echo '$newsconfig already exists; left unchanged'"
	echo "else"
	echo "	cp config $newsconfig"
	echo "	chmod +x $newsconfig"
	echo "fi"
	echo ": It is virtually certain that some of those control files"
	echo ": need modifying to suit your system.  In particular, you"
	echo ": should pick up a current 'active' file from your neighbors."
	echo ": done"
) >>doit.news
echo 'done'

echo
echo 'building again.root...'
>again.root
if test ! -w again.root
then
	echo 'It appears that I cannot create again.root.  Aborting.'
	exit 1
fi
(
	echo "umask $newsumask"
	echo 'set -x'
	if test " $sete" != " y"
	then
		echo ": installing setnewsids"
		echo "cp setnewsids $newsctl"
		echo "$chown root $newsctl/setnewsids"
		echo "chmod u+s $newsctl/setnewsids"
		echo ": done"
	fi
	echo ": setting uids for setuid programs..."
	them="$newsbin/input/newsspool $newsbin/relay/relaynews"
	if test " $chboth" = " y"
	then
		echo "$chown $newsuid.$newsgid $them"
	else
		echo "$chown $newsuid $them"
		echo "$chgrp $newsgid $them"
	fi
	echo "chmod u+s,g+s $them"
	echo ": done"
) >>again.root
echo 'done'

echo
chmod +x doit.root doit.bin doit.news again.root
echo 'You should now run doit.root as root (or as somebody with the power'
echo "to create $newsctl, $newsarts, and $newsbin"
echo "and run chown), doit.bin as $binuid, doit.news as $newsuid, and"
echo "again.root as root (or as somebody with the power to run chown),"
echo 'in that order.  Finally, you will want to add the contents of'
echo "'cron', or something similar, to your cron's work-to-be-done"
echo "file(s), and the contents of 'rc', or something similar, to"
echo '/etc/rc or whatever your system executes when booting.'
echo
echo '"make gclean" will clean up everything afterwards.  "make lclean"'
echo 'does a less drastic cleanup affecting only the library directories.'
echo '"make spotless" does "make gclean" and also removes the doit files.'
echo
echo 'Good luck and happy news reading.'
