IGNOREPATH=/etc:/home:/dev:/boot:/root:/tmp:/usr/local:/bin:/mnt:/var/log:/usr/sr
STRIPLIB=y
STRIPBIN=y

VERSION=2.8
PROGNAME="yptools $VERSION"
DESC="\
yptools (NIS servers and clients)                                      \n\
                                                                       \n\
NIS stands for Network Information Service.  NIS is usually used to    \n\
provide /etc/passwd and /etc/group information throughout the network. \n\
Most Sun-based networks run NIS, and Linux machines can take full      \n\
advantage of existing NIS service or provide NIS service themselves."

BUILD=1
MAINTAINER="Mark Post <mark.post@eds.com>"
SOURCE=
PKGNAME=yptools-$VERSION-s390-$BUILD
TAG=OPT

compile() {
   #
   # compile yp-tools
   #
   cd $TMP
   tar -yxvf $CWD/yp-tools-2.8.tar.bz2
   cd yp-tools-$VERSION/

   ./configure --prefix=/usr --disable-domainname \
               --build=s390-slackware-linux \
               --host=s390-slackware-linux \
               --target=s390-slackware-linux
   make clean
   ./configure --prefix=/usr --disable-domainname \
               --build=s390-slackware-linux \
               --host=s390-slackware-linux \
               --target=s390-slackware-linux
   make CFLAGS=-O2

   #
   # compile ypbind-3.3
   #
   cd $TMP
   tar -zxvf $CWD/ypbind-3.3.tar.gz
   cd ypbind-3.3/
   zcat $CWD/ypbind-3.3-glibc5.diff.gz | patch -p1 --backup --verbose --suffix=.orig
   zcat $CWD/ypbind-3.3-glibc-2.2.2.diff.gz | patch -p1 --backup --verbose --suffix=.orig
   cat $CWD/ypbind.daemon.c.diff | patch -p1 --backup --verbose --suffix=.orig2

   ./configure --prefix=/usr \
               s390-slackware-linux
   make clean
   ./configure --prefix=/usr \
               s390-slackware-linux
   make -i

   #
   # compile ypbind-mt
   #
   cd $TMP
   tar -yxvf $CWD/ypbind-mt-1.14.tar.bz2
   cd ypbind-mt-1.14/

   ./configure --prefix=/usr \
               --build=s390-slackware-linux \
               --host=s390-slackware-linux \
               --target=s390-slackware-linux
   make clean
   ./configure --prefix=/usr \
               --build=s390-slackware-linux \
               --host=s390-slackware-linux \
               --target=s390-slackware-linux
   make

   #
   # compile ypserv
   #
   cd $TMP
   tar -yxvf $CWD/ypserv-2.9.tar.bz2
   cd ypserv-2.9/

   ./configure --enable-fqdn \
               --enable-yppasswd \
               --build=s390-slackware-linux \
               --host=s390-slackware-linux \
               --target=s390-slackware-linux
   make clean
   ./configure --enable-fqdn \
               --enable-yppasswd \
               --build=s390-slackware-linux \
               --host=s390-slackware-linux \
               --target=s390-slackware-linux
   make

   # yptools is officially evil since it needs itself installed first.  Or
   # at least before ypmake is built.  Sigh.   
   cp yppush/yppush makedbm/makedbm /usr/local/sbin
 
   #
   # compile ypmake
   #
   cd $TMP
   tar -yxvf $CWD/ypmake-0.11.tar.bz2
   cd ypmake-0.11/

    ./configure
   make clean
    ./configure
   make

  ( cd /usr/local/sbin ; rm yppush makedbm )
}

install() {
   mkdir -p /package-yptools/etc/rc.d/

   #
   # install yp-tools
   #
   cd $TMP/yp-tools-$VERSION
   make install DESTDIR=/package-yptools

   mkdir -p /package-yptools/usr/doc/yp-tools-$VERSION
   cp -a ABOUT-NLS AUTHORS COPYING ChangeLog INSTALL NEWS README THANKS TODO \
       /package-yptools/usr/doc/yp-tools-$VERSION

   # Add etc/nsswitch.conf-nis as a full NIS+ example config file:
   zcat $CWD/nsswitch.conf-nis.gz > /package-yptools/etc/nsswitch.conf-nis.new

   ( cd man
     cp -p domainname.8 nisdomainname.8 ypdomainname.8 /package-yptools/usr/share/man/man8/
   )

    mv /package-yptools/var/yp/nicknames /package-yptools/var/yp/nicknames.new

   ( cd /package-yptools/usr/bin
     rm -rf ypchfn ypchsh
     ln -sf yppasswd ypchfn
     ln -sf yppasswd ypchsh
   )

   #
   # install ypbind-3.3
   #
   cd $TMP/ypbind-3.3
   make install DESTDIR=/package-yptools

   mkdir -p /package-yptools/usr/doc/ypbind-3.3
   cp -a COPYING INSTALL README TODO yp.conf.example \
       /package-yptools/usr/doc/ypbind-3.3

   mv /package-yptools/usr/sbin/ypbind /package-yptools/usr/sbin/ypbind-3.3
   mv /package-yptools/usr/man/man8/ypbind.8 /package-yptools/usr/man/man8/ypbind-3.3.8

   #
   # install ypbind-mt
   #
   cd $TMP/ypbind-mt-1.14/
   make install DESTDIR=/package-yptools

   mkdir -p /package-yptools/usr/doc/ypbind-mt-1.14
   cp -a ABOUT-NLS AUTHORS COPYING ChangeLog INSTALL NEWS README THANKS TODO \
       /package-yptools/usr/doc/ypbind-mt-1.14

   cat etc/yp.conf > /package-yptools/etc/yp.conf.new

   #
   # install ypserv
   #
   cd $TMP/ypserv-2.9/
   make install DESTDIR=/package-yptools

   mkdir -p /package-yptools/usr/doc/ypserv-2.9
   cp -a AUTHORS COPYING ChangeLog INSTALL NEWS README THANKS TODO \
       /package-yptools/usr/doc/ypserv-2.9

   zcat $CWD/rc.yp.gz > /package-yptools/etc/rc.d/rc.yp.new

   echo "# This file is part of the YP server package -- see 'man netgroup'" \
      > /package-yptools/etc/netgroup.new
   cat etc/netgroup >> /package-yptools/etc/netgroup.new

   cat etc/securenets > /package-yptools/var/yp/securenets.new

   ( cd /package-yptools/var/yp
     mv Makefile Makefile.new
   )

   #
   # install ypmake
   #
   cd $TMP/ypmake-0.11
   cp ypmake /package-yptools/usr/sbin

   mkdir -p /package-yptools/usr/lib/yp/ypmake
   cp -a aliases arrays automount config ethers group gshadow hosts netgroup \
         netid networks passwd protocols publickey rpc services shadow \
         ypservers /package-yptools/usr/lib/yp/ypmake

   cp -a ypmake.conf.sample /package-yptools/var/yp/ypmake.conf.new
   cp -a ypmake.conf.man /package-yptools/usr/man/man5/ypmake.conf.5
   cp -a ypmake.man /package-yptools/usr/man/man8/ypmake.8

   mkdir -p /package-yptools/usr/doc/ypmake-0.11/
   cp -a CHANGES README TODO /package-yptools/usr/doc/ypmake-0.11/

   mkdir -p /package-yptools/usr/man/man1
   ( cd /package-yptools/usr/share/man
     mv man1/* /package-yptools/usr/man/man1
     mv man5/* /package-yptools/usr/man/man5
     mv man8/* /package-yptools/usr/man/man8
   )
   rm -rf /package-yptools/usr/share/man
   ( cd /package-yptools/usr/man/
     for dir in 1 5 8; do
       ( cd man$dir
         rm -f *.gz
         gzip -9 *.$dir
       )
     done
   )

   rm /package-yptools/usr/sbin/yptest

   rmdir /package-yptools/bin
}

attributes() {
   chown -R root.bin $PKG/package-yptools/usr/bin \
                     $PKG/package-yptools/usr/sbin
   chmod 755 $PKG/package-yptools/etc/rc.d/rc.yp.new \
             $PKG/package-yptools/usr/bin/* \
             $PKG/package-yptools/usr/sbin/* \
             $PKG/package-yptools/usr/lib/yp/makedbm \
             $PKG/package-yptools/usr/lib/yp/mknetid \
             $PKG/package-yptools/usr/lib/yp/revnetgroup \
             $PKG/package-yptools/usr/lib/yp/yphelper \
             $PKG/package-yptools/usr/lib/yp/ypxfr
}

special() {
   cd $PKG
   mv package-yptools/* ./
   rmdir package-yptools/

   cd $CTL
   cat $CWD/slack-desc > slack-desc

   sed -e s'%package-yptools/%%g' doinst.sh > doinst.sh.new
   cat doinst.sh.new > doinst.sh
   rm doinst.sh.new

   cat $CWD/config.sh >> doinst.sh
   echo config etc/netgroup.new >> doinst.sh
   echo config etc/nsswitch.conf-nis.new >> doinst.sh
   echo config etc/rc.d/rc.yp.new >> doinst.sh
   echo config etc/yp.conf.new >> doinst.sh
   echo config var/yp/Makefile.new >> doinst.sh
   echo config var/yp/nicknames.new >> doinst.sh
   echo config var/yp/securenets.new >> doinst.sh
   echo config var/yp/ypmake.conf.new >> doinst.sh

   echo rm -f etc/nsswitch.conf.new etc/nsswitch.conf-nis.new etc/netgroup.new etc/yp.conf.new var/yp/nicknames.new var/yp/ypmake.conf.new var/yp/Makefile.new var/yp/securenets.new >> doinst.sh
return
   # make sure those directories we created still exist
   ( cd $PKG/var
     mkdir -p yp
     find . -type d -exec chown root.root {} \;
     find . -type d -exec chmod 755 {} \;
   )

   mkdir -p $PKG/etc-incoming
   cp $CWD/nsswitch.conf $PKG/etc-incoming
   cp $CWD/nsswitch.conf-nis $PKG/etc-incoming

   # now, update the doinst.sh script
   cat $CWD/doinst.sh >> $CTL/doinst.sh
}
