#!/bin/sh

. ./_blfsset.sh

APPNAME=ntp
VER=4.2.8p15
TARGET=$APPNAME-$VER
TARGETBALL=$DLD/$TARGET.tar.gz
TARGETDIR=$TARGET

echo $TARGET

. $WRK/_checkRequired.sh \
	IO-Socket-SSL
. $WRK/_checkOptions.sh  \
	libcap2 libevent libedit
. $WRK/_checkTarball.sh
. $WRK/_checkExit.sh "$1" || exit $?

unset MAKEFLAGS

cd $SRC
RemoveSrcDir
Extract

TimeStart

groupadd -g 87 ntp &&
useradd -c "Network Time Protocol" -d /var/lib/ntp -u 87 \
        -g ntp -s /bin/false ntp

cd $TARGETDIR

sed -e 's/"(\\S+)"/"?([^\\s"]+)"?/' \
    -i scripts/update-leap/update-leap.in

Configuring
./configure CFLAGS="-O2 -g -fPIC -fcommon $CFLAGS" \
            --prefix=/usr         \
            --bindir=/usr/sbin    \
            --sysconfdir=/etc     \
            --enable-linuxcaps    \
            --with-lineeditlibs=readline \
            --docdir=/usr/share/doc/ntp-$VER \
	1> $LOG/$TARGET.1_conf.log 2>&1 || exit 1

Making
make \
	1> $LOG/$TARGET.2_make.log 2>&1 || exit 1

Installing
porg -lp $TARGET "make install" \
	1> $LOG/$TARGET.3_install.log 2>&1 || exit 1

porg -lp+ $TARGET "\
install -v -o ntp -g ntp -d /var/lib/ntp" \
	1>> $LOG/$TARGET.3_install.log 2>&1 || exit 1

#install -v -m755 -d /usr/share/doc/ntp-$VER
#porg -lp+ $TARGET "\
#cp -v -R html/* /usr/share/doc/ntp-$VER/" \
#	1>> $LOG/$TARGET.3_install.log 2>&1 || exit 1

cat > /etc/ntp.conf << "EOF"
# Asia
server 0.asia.pool.ntp.org

# Australia
server 0.oceania.pool.ntp.org

# Europe
server 0.europe.pool.ntp.org

# North America
server 0.north-america.pool.ntp.org

# South America
server 2.south-america.pool.ntp.org

driftfile /var/lib/ntp/ntp.drift
pidfile   /var/run/ntpd.pid

leapfile  /var/lib/ntp/ntp.leapseconds
EOF
porg -lp+ $TARGET "\
touch /etc/ntp.conf" \
	1>> $LOG/$TARGET.3_install.log 2>&1 || exit 1

TimeEnd

cd ..
RemoveSrcDir
PorgingDone

