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

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

check() {
# Checking for configuration
# Downloading sources lists
INSTALLED="`ls -1 $PACKAGES/packages/|grep $PACKAGE-|cut -d "-" -f 1,2`"
$WGET -q ftp://ftp.isc.org/isc/dhcp/
NEW=`grep $PACKAGE index.html|grep .tar|cut -d / -f 6|grep -v latest|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.isc.org/isc/dhcp/$SRC.tar.gz
}

build() {
# Creating new
tar zxvf $DOWNL/$SRC.tar.gz
cd $SRC
./configure
make
mkdir -p $PKG/usr/sbin $PKG/sbin
cat client/scripts/linux > $PKG/sbin/dhclient-script
chmod 700 $PKG/sbin/dhclient-script
( cd work.linux-2.2
  strip server/dhcpd client/dhclient relay/dhcrelay
  cat server/dhcpd > $PKG/usr/sbin/dhcpd
  cat relay/dhcrelay > $PKG/usr/sbin/dhcrelay
  cat client/dhclient > $PKG/sbin/dhclient )
mkdir -p $PKG/usr/man/man5
mkdir -p $PKG/usr/man/man8
for dir in client server ; do
  cd $dir
  for file in *.5 ; do
    cat $file | sed -e "s#ETCDIR#/etc#g" -e "s#DBDIR#/var/db#g" \
      -e "s#RUNDIR#/var/run#g" | gzip -9c > $PKG/usr/man/man5/$file.gz
  done
  for file in *.8 ; do
    cat $file | sed -e "s#ETCDIR#/etc#g" -e "s#DBDIR#/var/db#g" \
      -e "s#RUNDIR#/var/run#g" | gzip -9c > $PKG/usr/man/man8/$file.gz
  done
  cd ..
done
cat relay/dhcrelay.8 | sed -e "s#ETCDIR#/etc#g" -e "s#DBDIR#/var/db#g" \
  -e "s#RUNDIR#/var/run#g" | gzip -9c > $PKG/usr/man/man8/dhcrelay.8.gz
chmod 755 $PKG/usr/sbin/*
    postbuild
}

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

