#!/bin/sh
#
# kTm port by Juzer
#
#       regards to hns & psych
#

# local config:
BUILD="1"
PACKAGE="coreutils"

check() {
# Checking for configuration
# Downloading sources lists
INSTALLED="`ls -1 /var/packages/packages/|grep coreutils|cut -d "-" -f 1,2`"
$WGET -q ftp://ftp.gnu.org/gnu/coreutils/
NEW=`grep coreutils index.html|grep .tar|cut -d / -f 6|cut -d '"' -f 1|sed -e s/.tar.*//|tail -1`
#Checking for new version
    checkpkg
# clean
rm index.html
}

download() {
# Downloading version from "${VERFILE}"
$WGET -P $DOWNL ftp://ftp.gnu.org/gnu/coreutils/$SRC.tar.bz2
}

build() {
# Creating new
tar jxvf $DOWNL/$SRC.tar.bz2
cd $SRC
./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    $TARGET || exit
make
make install DESTDIR=$PKG
zcat $CWD/files/dircolors.c.gz > src/dircolors.c
zcat $CWD/files/dircolors.h.gz > src/dircolors.h
( cd src ; make )
cat src/dircolors > $PKG/usr/bin/dircolors
for dupe in hostname kill su uptime ; do
    rm -f usr/bin/${dupe} usr/sbin/${dupe} usr/man/man?/${dupe}.*
done
# These things have always been in /bin on Linux:
cd $PKG
mkdir -p bin
for move in cat chgrp chmod chown cp cut date dd df dircolors du echo false head \
ln ls mkdir mkfifo mknod mv pwd rm rmdir shred sleep stty sync touch true uname ; do
    mv usr/bin/${move} bin
    ln -sf ../../bin/${move} usr/bin/${move}
done
ln -sf $PKG/bin/chroot /usr/sbin/chroot
rm -f $PKG/usr/info/dir
mkdir -p $PKG/etc
zcat $CWD/files/DIR_COLORS.gz > $PKG/etc/DIR_COLORS
# Add ginstall links:
( cd $PKG/usr/bin ; ln -sf install ginstall )
( cd $PKG/usr/man/man1 ; ln -sf install.1.gz ginstall.1.gz )
strip --strip-unneeded $PKG/usr/bin/*
strip --strip-unneeded $PKG/usr/sbin/*
    postbuild
}

source "${DATA:-/usr/lib/ktm}/ktm.ports.sh"
