IGNOREPATH=/etc:/home:/var:/dev:/boot:/root:/tmp:/usr/local:/mnt:/lib:/usr/src
STRIPLIB=y
STRIPBIN=y

VERSION=2.12
PROGNAME="util-linux $VERSION"
DESC="\
util-linux (a huge collection of essential utilities)                  \n\
                                                                       \n\
adjtimex agetty arch blockdev cal cfdisk chkdupexe clear clock col     \n\
colcrt colrm column ctrlaltdel cytune ddate dmesg dnsdomainname        \n\
domainname elvtune fdformat fdisk fsck.cramfs fsck.minix getopt        \n\
getoptprog hexdump hostname hwclock ipcrm ipcs isosize jaztool line    \n\
logger look losetup mcookie mesg mkfs mkfs.bfs mkfs.cramfs mkfs.minix  \n\
mkswap more mount namei nisdomainname pg pivot_root ramsize raw rdev   \n\
readprofile rename renice reset rev rootflags script setfdprm          \n\
setserial setsid setterm sfdisk sln strings swapoff swapon tput tunelp \n\
ul umount update vidmode wall whereis write ypdomainname ziptool"

BUILD=1
MAINTAINER="Mark Post <mark.post@eds.com>"
SOURCE=various
PKGNAME=util-linux-$VERSION-s390-$BUILD
#adjtimex
#http://ibiblio.org/pub/Linux/system/admin/time
#
#bsdstrings
#unknown
#
#net-tools
#http://www.tazenda.demon.co.uk/phil/net-tools/
#
#setserial
#http://sourceforge.net/projects/setserial/
#
#updated
#ftp://sunsite.unc.edu/pub/Linux/system/daemons/
#
#util-linux
#http://ftp.kernel.org/pub/linux/utils/util-linux/
#
#ziptool
#ftp://wolfpack.twu.net/users/wolfpack/
#
TAG=ADD

compile() {
   #
   # net-tools
   #
   tar -yxvf $CWD/net-tools-1.60.tar.bz2
   cd net-tools-1.60/
   zcat $CWD/net-tools.diff.gz | patch -p1

   make

   #
   # setserial
   #
   cd $TMP
   tar -zxvf $CWD/setserial-2.17.tar.gz
   cd setserial-2.17/
   zcat $CWD/setserial-rc.serial.diff.gz | patch -E -p1 --verbose
   cp -vp /usr/share/libtool/config.* ./
   ./configure --prefix=/usr

   make

   #
   # bsdstrings
   #
   cd $TMP
   tar -zxvf $CWD/bsdstrings.tar.gz
   cd bsdstrings/
   make

   #
   # adjtimex
   #
   cd $TMP
   tar -zxvf $CWD/adjtimex-1.13.tar.gz
   cd adjtimex-1.13/
   chown -R root.root .
   cat $CWD/adjtimex.c.diff | patch -p1
   CFLAGS=-O2 ./configure --prefix=/usr

   make

   #
   # util-linux
   #
   cd $TMP
   tar -yxvf $CWD/util-linux-$VERSION.tar.bz2
   cd util-linux-$VERSION/
   chown -R root.root .

   zcat $CWD/util-linux.MCONFIG.diff.gz | patch -p1
   
   ./configure
   make

   #
   # updated
   #
   cd $TMP
   tar -zxvf $CWD/updated-2.11.tar.gz
   cd updated-2.11/
   make

   #
   # ziptool
   #
   cd $TMP
   tar -zxvf $CWD/ziptool-1.3.tar.gz
   cd ziptool-1.3

   make
}

install() {
   mkdir /package-util-linux
   ( cd /package-util-linux
     tar -zxvf $CWD/_util-linux.tar.gz
     rm -rf install sbin/rdev
     cd /package-util-linux/usr/man/man1
     # We have to uncompress this so that the compress step doesn't delete it first
     gzip -d clear.1.gz
   )

   #
   # net-tools
   #
   cd $TMP/net-tools-1.60/
   # The only thing we want out of here is hostname and the symlinks to it
   cp -a hostname /package-util-linux/bin
   ( cd /package-util-linux/bin
     ln -fs hostname /package-util-linux/bin/dnsdomainname
     ln -fs hostname /package-util-linux/bin/ypdomainname
     ln -fs hostname /package-util-linux/bin/nisdomainname
     ln -fs hostname /package-util-linux/bin/domainname
   )
   cd man/en_US
   cp -p hostname.1 dnsdomainname.1 nisdomainname.1 ypdomainname.1 domainname.1 \
      /package-util-linux/usr/man/man1/


   #
   # bsdstrings
   #
   cd $TMP/bsdstrings
   cp -a strings /package-util-linux/usr/bin/strings
   cp -a strings.1 /package-util-linux/usr/man/man1/strings.1


   #
   # adjtimex
   #
   cd $TMP/adjtimex-1.13
   make install prefix=/package-util-linux/usr bindir=/package-util-linux/sbin

   mkdir -p /package-util-linux/usr/doc/adjtimex-1.13/
   cp -a COPYING COPYRIGHT ChangeLog README README.ru adjtimex.lsm \
      /package-util-linux/usr/doc/adjtimex-1.13/


   #
   # util-linux
   #
   cd $TMP/util-linux-$VERSION
   make install BINDIR=/package-util-linux/bin \
                SBINDIR=/package-util-linux/sbin \
                USRBINDIR=/package-util-linux/usr/bin \
                USRSBINDIR=/package-util-linux/usr/sbin \
                ETCDIR=/package-util-linux/etc \
                MANDIR=/package-util-linux/usr/man \
                GETOPTDIR=/package-util-linux/usr/share/misc/getopt/ \
                INFODIR=/package-util-linux/usr/info \
                MOREHELPDIR=/package-util-linux/usr/lib \
                gnulocaledir=/package-util-linux/usr/share/locale \
                localedir=/package-util-linux/usr/share/locale

   cp -a mount/pivot_root.2 /package-util-linux/usr/man/man2/
   cp -a misc-utils/reset.sh /package-util-linux/usr/bin/reset
   cp -a misc-utils/reset.1 /package-util-linux/usr/man/man1/

   rm /package-util-linux/usr/bin/last \
      /package-util-linux/usr/bin/tailf \
      /package-util-linux/usr/man/man1/last.1

   ( cd /package-util-linux/
     mv usr/bin/getopt usr/bin/setterm bin/
     mv sbin/cfdisk sbin/ctrlaltdel sbin/sfdisk usr/sbin/
     mv sbin/sln bin/
     mv usr/sbin/readprofile usr/sbin/tunelp usr/bin/
     # We want the fdparm from $CWD/_util-linux.tar.gz, and not the one from the package
     tar -zxvf $CWD/_util-linux.tar.gz etc/fdprm
   )

   ( cd /package-util-linux/sbin
     rm -rf mount  ; ln -sf /bin/mount mount
     rm -rf umount ; ln -sf /bin/umount umount
     rm -rf clock  ; ln -sf hwclock clock
   )

   ( cd /package-util-linux/usr/bin
     rm -rf more ; ln -sf /bin/more more
   )

   ( cd /package-util-linux/bin
     rm -rf getoptprog ; ln -sf getopt getoptprog
   )

   mkdir -p /package-util-linux/usr/doc/util-linux-$VERSION/
   cp -a HISTORY INSTALL hwclock/README* \
         fdisk/README* login-utils/README* misc-utils/README* \
         mount/README* text-utils/LICENSE.pg \
         text-utils/README* /package-util-linux/usr/doc/util-linux-$VERSION/
   cp -a getopt/README /package-util-linux/usr/doc/util-linux-$VERSION/README.getopt-1.1.3


   #
   # serial
   #   This package has to be installed after util-linux because that package
   #   also has a setserial binary, and we want this one.
   #
   cd $TMP/setserial-2.17
   make install DESTDIR=/package-util-linux
   ( cd /package-util-linux
     mv bin/setserial sbin/
   )
   cat setserial > /package-util-linux/sbin/setserial
   cat rc.serial > /package-util-linux/etc/rc.d/rc.serial
   cat serial.conf > /package-util-linux/etc/serial.conf


   #
   # updated
   #
   cd $TMP/updated-2.11/
   make install BINDIR=/package-util-linux/sbin MANDIR=/package-util-linux/usr/man/man8

   mkdir -p /package-util-linux/usr/doc/updated-2.11/
   cp -a update.lsm /package-util-linux/usr/doc/updated-2.11/


   #
   # ziptool
   #
   cd $TMP/ziptool-1.3
   make install INSTALL_BIN_DIR=/package-util-linux/sbin \
                INSTALL_MAN_DIR=/package-util-linux/usr/man

   # We have to uncompress this so that the compress step doesn't delete it first
   cat ziptool.1.gz | gzip -d > /package-util-linux/usr/man/man1/ziptool.1

   mkdir -p /package-util-linux/usr/doc/ziptool-1.3/
   cp -a README /package-util-linux/usr/doc/ziptool-1.3/


   # Don't ask me why Pat does this.  I don't know.
   cp -p /usr/bin/tput /package-util-linux/usr/bin/tput

   rm -rf /package-util-linux/usr/man/man1/tailf.1
   ( for dir in 1 2 5 8; do
     ( cd /package-util-linux/usr/man/man$dir
       rm -f *.gz
       gzip -9 *.$dir
     )
     done
   )

   ( cd /package-util-linux/usr/man/man1
     rm -rf jaztool.1 ; ln -sf ziptool.1.gz jaztool.1.gz
   )

   ( cd /package-util-linux/usr/info
       rm -f *.gz
       gzip -9 *
   )
}

attributes() {
   chown -R root.bin $PKG/package-util-linux/bin \
                     $PKG/package-util-linux/sbin \
                     $PKG/package-util-linux/usr/bin \
                     $PKG/package-util-linux/usr/sbin
   chown root.tty $PKG/package-util-linux/usr/bin/wall \
                 $PKG/package-util-linux/usr/bin/write
   chmod 755 $PKG/package-util-linux/usr/bin/reset
   chmod 2555 $PKG/package-util-linux/usr/bin/wall \
              $PKG/package-util-linux/usr/bin/write
   find $PKG/package-util-linux/usr/man -type f | xargs chmod 644
   chmod 644 $PKG/package-util-linux/usr/share/misc/getopt/*
   chmod 1777 $PKG/package-util-linux/var/lock/
}

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

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

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

