#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-tcpip
SRC=/devel/manpagesrc
INFO=/devel/info-pages/usr/info
TEX=/devel/texinfo-docs

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
if [ ! -d $PKG ]; then
  mkdir -p $PKG # place for the package to be built
fi

# Explode the package framework:
cd $PKG
tar xzvf $CWD/_tcpip.tar.gz

# Function to handle manpage source:
man2gz () { # $1 is source page name, $2 is target name for preformatted
            # output (full path && name) and $3 is the same, but for the
            # source.
  mkdir -p `dirname $2`
  groff -Tascii -mandoc $1 | gzip -9c > $2
  if [ ! "$3" = "" ]; then
    mkdir -p `dirname $3`
    cat $1 > $3 
  fi 
}

echo "+==================+"
echo "| net-tools-1.1.79 |"
echo "+==================+"
cd $TMP
tar xzvf $CWD/net-tools-1.1.79.tar.gz
cd net-tools
zcat $CWD/net-tools-1.1.79.diff.gz | patch
touch config.h
make
cat arp > $PKG/sbin/arp
cat ifconfig > $PKG/sbin/ifconfig
cat plipconfig > $PKG/sbin/plipconfig
cat rarp > $PKG/sbin/rarp
cat route > $PKG/sbin/route
# cat hostname > $PKG/bin/hostname # same binary already comes with util-linux
cat netstat > $PKG/bin/netstat
cat slattach > $PKG/usr/sbin/slattach
cd man
man2gz arp.8 $PKG/usr/man/preformat/cat8/arp.8.gz
#man2gz dnsdomainname.1 $PKG/usr/man/preformat/cat1/dnsdomainname.1.gz
( cd $SRC/usr/man/man1 ; ln -sf hostname.1.gz dnsdomainname.1.gz )
man2gz hostname.1 $PKG/usr/man/preformat/cat1/hostname.1.gz
man2gz ifconfig.8 $PKG/usr/man/preformat/cat8/ifconfig.8.gz
man2gz netstat.8 $PKG/usr/man/preformat/cat8/netstat.8.gz
man2gz plipconfig.8 $PKG/usr/man/preformat/cat8/plipconfig.8.gz
man2gz rarp.8 $PKG/usr/man/preformat/cat8/rarp.8.gz
man2gz resolver.5 $PKG/usr/man/preformat/cat5/resolver.5.gz
man2gz route.8 $PKG/usr/man/preformat/cat8/route.8.gz
man2gz slattach.8 $PKG/usr/man/preformat/cat8/slattach.8.gz

echo "+===============+"
echo "| NetKit-B-0.05 |"
echo "+===============+"
cd $TMP
tar xzvf $CWD/NetKit-B-0.05.tar.gz
cd NetKit-B-0.05
zcat $CWD/NetKit-B-0.05.diff.gz | patch
make
cd fingerd
cat fingerd > $PKG/usr/sbin/in.fingerd
man2gz fingerd.8 $PKG/usr/man/preformat/cat8/in.fingerd.8.gz $SRC/usr/man/man8/in.fingerd.8
cd ../ftp
cat ftp > $PKG/bin/ftp
man2gz ftp.1 $PKG/usr/man/preformat/cat1/ftp.1.gz $SRC/usr/man/man1/ftp.1
cd ../inetd
cat inetd > $PKG/usr/sbin/inetd
man2gz inetd.8 $PKG/usr/man/preformat/cat8/inetd.8.gz $SRC/usr/man/man8/inetd.8
cd ../ping
cat ping > $PKG/bin/ping
man2gz ping.8 $PKG/usr/man/preformat/cat8/ping.8.gz $SRC/usr/man/man8/ping.8
cd ../portmap
man2gz portmap.8 $PKG/usr/man/preformat/cat8/portmap.8.gz $SRC/usr/man/man8/portmap.8
cd ../rcp
cat rcp > $PKG/usr/bin/rcp
man2gz rcp.1 $PKG/usr/man/preformat/cat1/rcp.1.gz $SRC/usr/man/man1/rcp.1
cd ../rexecd
cat rexecd > $PKG/usr/sbin/in.rexecd
man2gz rexecd.8 $PKG/usr/man/preformat/cat8/rexecd.8.gz $SRC/usr/man/man8/rexecd.8
cd ../rlogin
cat rlogin > $PKG/usr/bin/rlogin
man2gz rlogin.1 $PKG/usr/man/preformat/cat1/rlogin.1.gz $SRC/usr/man/man1/rlogin.1
cd ../rlogind
cat rlogind > $PKG/usr/sbin/in.rlogind
man2gz rlogind.8 $PKG/usr/man/preformat/cat8/in.rlogind.8.gz $SRC/usr/man/man8/in.rlogind.8
cd ../routed
cat routed > $PKG/usr/sbin/routed
man2gz routed.8 $PKG/usr/man/preformat/cat8/routed.8.gz $SRC/usr/man/man8/routed.8
cd ../rpc.rusersd
cat rusersd > $PKG/usr/sbin/rpc.rusersd
man2gz rpc.rusersd.8 $PKG/usr/man/preformat/cat8/rpc.rusersd.8.gz $SRC/usr/man/man8/rpc.rusersd.8
cd ../rpc.rwalld
cat rwalld > $PKG/usr/sbin/rpc.rwalld
man2gz rpc.rwalld.8 $PKG/usr/man/preformat/cat8/rpc.rwalld.8.gz $SRC/usr/man/man8/rpc.rwalld.8
cd ../rpcgen.new
cat rpcgen > $PKG/usr/bin/rpcgen
man2gz rpcgen.1 $PKG/usr/man/preformat/cat1/rpcgen.1.gz $SRC/usr/man/man1/rpcgen.1
cd ../rpcinfo
cat rpcinfo > $PKG/usr/sbin/rpcinfo
man2gz rpcinfo.8 $PKG/usr/man/preformat/cat8/rpcinfo.8.gz $SRC/usr/man/man8/rpcinfo.8
cd ../rsh
cat rsh > $PKG/usr/bin/rsh
man2gz rsh.1 $PKG/usr/man/preformat/cat1/rsh.1.gz $SRC/usr/man/man1/rsh.1
cd ../rshd
cat rshd > $PKG/usr/sbin/in.rshd
man2gz rshd.8 $PKG/usr/man/preformat/cat8/in.rshd.gz $SRC/usr/man/man8/in.rshd.8
cd ../rusers
cat rusers > $PKG/usr/bin/rusers
man2gz rusers.1 $PKG/usr/man/preformat/cat1/rusers.1.gz $SRC/usr/man/man1/rusers.1
cd ../rwall
cat rwall > $PKG/usr/bin/rwall
man2gz rwall.1 $PKG/usr/man/preformat/cat1/rwall.1.gz $SRC/usr/man/man1/rwall.1
cd ../rwho
cat rwho > $PKG/usr/bin/rwho
man2gz rwho.1 $PKG/usr/man/preformat/cat1/rwho.1.gz $SRC/usr/man/man1/rwho.1
cd ../sliplogin
cat sliplogin > $PKG/usr/sbin/sliplogin
man2gz sliplogin.8 $PKG/usr/man/preformat/cat8/sliplogin.8.gz $SRC/usr/man/man8/sliplogin.8
cd ../talk
cat talk > $PKG/usr/bin/talk
man2gz talk.1 $PKG/usr/man/preformat/cat1/talk.1.gz $SRC/usr/man/man1/talk.1
cd ../talkd
cat talkd > $PKG/usr/sbin/in.talkd
man2gz talkd.8 $PKG/usr/man/preformat/cat8/in.talkd.8.gz $SRC/usr/man/man8/in.talkd.8
cd ../telnet
cat telnet > $PKG/bin/telnet
man2gz telnet.1 $PKG/usr/man/preformat/cat1/telnet.1.gz $SRC/usr/man/man1/telnet.1
cd ../telnetd
cat telnetd > $PKG/usr/sbin/in.telnetd
man2gz telnetd.8 $PKG/usr/man/preformat/cat8/in.telnetd.8.gz $SRC/usr/man/man8/in.telnetd.8
cd ../tftp
cat tftp > $PKG/usr/bin/tftp
man2gz tftp.1 $PKG/usr/man/preformat/cat1/tftp.1.gz $SRC/usr/man/man1/tftp.1
cd ../tftpd
cat tftpd > $PKG/usr/sbin/in.tftpd
man2gz tftpd.8 $PKG/usr/man/preformat/cat8/in.tftpd.8.gz $SRC/usr/man/man8/in.tftpd.8
cd ../timed/timed
cat timed > $PKG/usr/sbin/in.timed
man2gz timed.8 $PKG/usr/man/preformat/cat8/timed.8.gz $SRC/usr/man/man8/timed.8
cd ../timedc
cat timedc > $PKG/usr/sbin/timedc
man2gz timedc.8 $PKG/usr/man/preformat/cat8/timedc.8.gz $SRC/usr/man/man8/timedc.8

echo "+========+"
echo "| finger |"
echo "+========+"
cd $TMP
tar xzvf $CWD/finger.tar.gz
cd finger
make
cat finger > $PKG/usr/bin/finger
man2gz finger.1 $PKG/usr/man/preformat/cat1/finger.1.gz $SRC/usr/man/man1/finger.1

echo "+===========+"
echo "| portmap_3 |"
echo "+===========+"
cd $TMP
tar xzvf $CWD/portmap_3.tar.gz
cd portmap_3
make
strip portmap pmap_dump pmap_set
cat portmap > $PKG/usr/sbin/rpc.portmap
cat pmap_dump > $PKG/usr/sbin/pmap_dump
cat pmap_set > $PKG/usr/sbin/pmap_set

echo "+=============+"
echo "| fwhois-1.00 |"
echo "+=============+"
cd $TMP
tar xzvf $CWD/fwhois-1.00.tar.gz
cd fwhois-1.00
make
cat fwhois > $PKG/usr/bin/fwhois

echo "+================+"
echo "| popclient-2.21 |"
echo "+================+"
cd $TMP
tar xzvf $CWD/popclient-2.21.tar.gz
cd pop
make
strip popclient
cat popclient > $PKG/usr/bin/popclient
man2gz popclient.1L $PKG/usr/man/preformat/cat1/popclient.1.gz $SRC/usr/man/man1/popclient.1

echo "+=============+"
echo "| ruptime-570 |"
echo "+=============+"
cd $TMP
tar xzvf $CWD/ruptime-570.tar.gz
cd ruptime
make
cat ruptime > $PKG/usr/bin/ruptime
man2gz ruptime.1 $PKG/usr/man/preformat/cat1/ruptime.1.gz $SRC/usr/man/man1/ruptime.1

echo "+===============+"
echo "| NetKit-A-0.06 |"
echo "+===============+"
cd $TMP
tar xzvf $CWD/NetKit-A-0.06.tar.gz
cd NetKit-A-0.06
make
cd ytalk-3.0.1
cp Makefile.old Makefile
make CFLAGS=-O2 LDFLAGS=-s
cat ytalk > $PKG/usr/bin/ytalk
man2gz ytalk.1 $PKG/usr/man/preformat/cat1/ytalk.1.gz $SRC/usr/man/man1/ytalk.1
cd ../pidentd-2.2
strip in.identd
cat in.identd > $PKG/usr/sbin/in.identd
man2gz identd.8 $PKG/usr/man/preformat/cat8/in.identd.8.gz $SRC/usr/man/man8/in.identd.8
cd ../nfs-server-2.0
cat rpc.mountd > $PKG/usr/sbin/rpc.mountd
cat rpc.nfsd > $PKG/usr/sbin/rpc.nfsd
cat showmount > $PKG/usr/sbin/showmount
man2gz mountd.8 $PKG/usr/man/preformat/cat8/mountd.8.gz $SRC/usr/man/man8/mountd.8
man2gz nfsd.8 $PKG/usr/man/preformat/cat8/nfsd.8.gz $SRC/usr/man/man8/nfsd.8
man2gz showmount.8 $PKG/usr/man/preformat/cat8/showmount.8.gz $SRC/usr/man/man8/showmount.8
man2gz exports.5 $PKG/usr/man/preformat/cat5/exports.5.gz $SRC/usr/man/man5/exports.5
cd ../tcp_wrapper-6.3
strip tcpd safe_finger try try-from
cat tcpd > $PKG/usr/sbin/tcpd
make clean
make REAL_DAEMON_DIR=/usr/sbin/real-daemon-dir linux
strip tcpd safe_finger try try-from
cat tcpd > $PKG/usr/sbin/real-daemon-dir/tcpd
cat safe_finger > $PKG/usr/sbin/real-daemon-dir/safe_finger
cat try > $PKG/usr/sbin/real-daemon-dir/try
cat try-from > $PKG/usr/sbin/real-daemon-dir/try-from
cd ../traceroute-4.4BSD
cc -s -o traceroute traceroute.o
cat traceroute > $PKG/usr/bin/traceroute
man2gz traceroute.8 $PKG/usr/man/preformat/cat8/traceroute.8.gz $SRC/usr/man/man8/traceroute.8

echo "+=============+"
echo "| wu-ftpd-2.4 |"
echo "+=============+"
cd $TMP
tar xzvf $CWD/wu-ftpd-2.4.tar.gz
cd wu-ftpd-2.4
zcat $CWD/wu-ftpd-2.4.diff.gz | patch
build lnx
cd bin
strip *
cat ckconfig > $PKG/usr/sbin/ckconfig
cat ftpcount > $PKG/usr/bin/ftpcount
cat ftpd > $PKG/usr/sbin/wu.ftpd
cat ftpshut > $PKG/usr/bin/ftpshut
cat ftpwho > $PKG/usr/bin/ftpwho
cd ../doc
man2gz ftpaccess.5 $PKG/usr/man/preformat/cat5/ftpaccess.5.gz $SRC/usr/man/man5/ftpaccess.5
man2gz ftpconversions.5 $PKG/usr/man/preformat/cat5/ftpconversions.5.gz $SRC/usr/man/man5/ftpconversions.5
man2gz ftpcount.1 $PKG/usr/man/preformat/cat1/ftpcount.1.gz $SRC/usr/man/man1/ftpcount.1
man2gz ftpd.8 $PKG/usr/man/preformat/cat8/wu.ftpd.8.gz $SRC/usr/man/man8/wu.ftpd.8
man2gz ftphosts.5 $PKG/usr/man/preformat/cat5/ftphosts.5.gz $SRC/usr/man/man5/ftphosts.5
man2gz ftpshut.8 $PKG/usr/man/preformat/cat8/ftpshut.8.gz $SRC/usr/man/man8/ftpshut.8
man2gz ftpwho.1 $PKG/usr/man/preformat/cat1/ftpwho.1.gz $SRC/usr/man/man1/ftpwho.1
man2gz realpath.3 $PKG/usr/man/preformat/cat3/realpath.3.gz $SRC/usr/man/man3/realpath.3
man2gz xferlog.5 $PKG/usr/man/preformat/cat5/xferlog.5.gz $SRC/usr/man/man5/xferlog.5

echo "+============+"
echo "| yp-clients |"
echo "+============+"
cd $TMP
tar xzvf $CWD/yp-clients.tar.gz
cd yp.bin
make
strip ypbind
cat ypbind > $PKG/usr/sbin/ypbind
cd domainname
strip domainname
cat domainname > $PKG/bin/domainname-yp
cd ../ypcat
strip ypcat
cat ypcat > $PKG/usr/bin/ypcat
cd ../ypmatch
strip ypmatch
cat ypmatch > $PKG/usr/bin/ypmatch
cd ../yppoll
strip yppoll
cat yppoll > $PKG/usr/bin/yppoll
cd ../ypset
strip ypset
cat ypset > $PKG/usr/bin/ypset
cd ../ypwhich
strip ypwhich
cat ypwhich > $PKG/usr/bin/ypwhich

echo "+==============+"
echo "| telnetsnoopd |"
echo "+==============+"
cd $TMP
tar xzvf $CWD/telnetsnoopd.tar.gz
cd telnetsnoopd
make
cat telnetsnoopd/telnetd > $PKG/usr/sbin/in.telnetsnoopd

echo "+===============+"
echo "| ttysnoop-0.11 |"
echo "+===============+"
cd $TMP
tar xzvf $CWD/ttysnoop-0.11.tar.gz
cd ttysnoop-0.11
make
strip ttysnoop ttysnoops
cat ttysnoops > $PKG/bin/ttysnoops
cat ttysnoop > $PKG/usr/sbin/ttysnoop
man2gz ttysnoop.8 $PKG/usr/man/preformat/cat8/ttysnoop.8.gz $SRC/usr/man/man8/ttysnoop.8

echo "+==============+"
echo "| netdate-1.16 |"
echo "+==============+"
cd $TMP
tar xzvf $CWD/netdate-1.16.tar.gz
cd netdate
make
strip netdate
cat netdate > $PKG/usr/sbin/netdate
man2gz netdate.8 $PKG/usr/man/preformat/cat8/netdate.8.gz $SRC/usr/man/man8/netdate.8

echo "+===============+"
echo "| linux_pcnfsd2 |"
echo "+===============+"
cd $TMP
tar xzvf $CWD/linux_pcnfsd2.tar.gz
cd pcnfsd_linux2
make -f Makefile.linux
cd linux
strip clnt.pcnfsd rpc.pcnfsd
cat clnt.pcnfsd > $PKG/usr/sbin/clnt.pcnfsd
cat rpc.pcnfsd > $PKG/usr/sbin/rpc.pcnfsd

echo "+=======+"
echo "| rwhod |"
echo "+=======+"
cd $TMP
tar xzvf $CWD/rwhod-519.tar.gz
cd rwhod
make
cat rwhod > $PKG/usr/sbin/rwhod
man2gz rwhod.8 $PKG/usr/man/preformat/cat8/rwhod.8.gz $SRC/usr/man/man8/rwhod.8

echo "+========+"
echo "| bwnfsd |"
echo "+========+"
cd $TMP
tar xzvf $CWD/bwnfsd.tar.gz
cd bwnfsd
make linux
strip bwnfsd
cat bwnfsd > $PKG/usr/sbin/rpc.bwnfsd

echo "+===============+"
echo "| nntp-1.5.11tp |"
echo "+===============+"
cd $TMP
tar xzvf $CWD/nntp-1.5.11tp-linux.tar.gz
cd nntp.1.5.11t
zcat $CWD/nntp-1.5.11tp-linux.diff.gz | patch -p1
make server
cd server
strip nntpd
cat nntpd > $PKG/usr/sbin/in.nntpd
man2gz $CWD/nntpd.8 $PKG/usr/man/preformat/cat8/in.nntpd.8.gz $SRC/usr/man/man8/in.nntpd
cd ..
make client
cd inews
strip inews
cat inews > $PKG/usr/bin/inews-nntp

echo "+==============+"
echo "| pop3d-1.00.4 |"
echo "+==============+"
cd $TMP
tar xzvf $CWD/pop3d-1.00.4.tar.gz
cd pop3d
make
cat pop3d > $PKG/usr/sbin/in.pop3d
mkdir -p $PKG/usr/man/preformat/cat8
gzip -9c pop3d.man > $PKG/usr/man/preformat/cat8/in.pop3d.8.gz

echo "+===========+"
echo "| ncftp 183 |"
echo "+===========+"
cd $TMP
tar xzvf $CWD/ncftp183.tar.gz
cd ncftp183/readline-2.0
configure --prefix=/usr
make CFLAGS=-O2 LDFLAGS=-s
cd ..
make
cat ncftp > $PKG/usr/bin/ncftp
man2gz ncftp.1 $PKG/usr/man/preformat/cat1/ncftp.1.gz $SRC/usr/man/man1/ncftp.1

# Build the package:
cd $PKG
tar czvf $TMP/tcpip.tgz .

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/net-tools
  rm -rf $TMP/NetKit-B-0.05
  rm -rf $TMP/NetKit-A-0.06
  rm -rf $TMP/finger
  rm -rf $TMP/portmap_3
  rm -rf $TMP/fwhois-1.00
  rm -rf $TMP/pop
  rm -rf $TMP/wu-ftpd-2.4
  rm -rf $TMP/telnetsnoopd
  rm -rf $TMP/ttysnoop-0.11
  rm -rf $TMP/netdate
  rm -rf $TMP/pcnfsd_linux2
  rm -rf $TMP/rwhod
  rm -rf $TMP/bwnfsd
  rm -rf $TMP/nntp.1.5.11t
  rm -rf $TMP/pop3d
  rm -rf $TMP/ncftp183
  rm -rf $TMP/ruptime
  rm -rf $TMP/yp.bin
  rm -rf $PKG
fi