NAME=openntpd
VERSION=3.9p1
SOURCE=(ftp://ftp.openbsd.org/pub/OpenBSD/OpenNTPD/openntpd-$VERSION.tar.gz
	rc.ntpd )
BUILD=1
OPTIMIZE=${OPTIMIZE:-"-O2"}

build() {
	_explode 0
	cd openntpd-$VERSION

	# configure options
	# --with-builtin-arc4random
	#     This is to avoid dependency on OpenSSL. In practice everyone
	#     should have OpenSSL but this option adds only a few bytes to
	#     the ntpd binary.
	$CONFIGURE \
		--with-builtin-arc4random \
		--with-privsep-user=ntp \
		--with-privsep-path=/var/empty
	make
	make DESTDIR="$PKG" install

	_new 0 ${SYSCONFDIR#/}/ntpd.conf

	mkdir $PKG/etc/rc.d
	cat ${SOURCE[1]} > $PKG/etc/rc.d/rc.ntpd
	_new_delete 0 etc/rc.d/rc.ntpd

	_doc 0 openntpd-$VERSION ChangeLog CREDITS LICENCE README

	cat << "EOF" >> $PKG/install/doinst.sh

# If the ntp user/group don't exist, add them:
if grep "^ntp:x:" etc/passwd 1> /dev/null 2> /dev/null ; then
  true
else
  echo "ntp:x:38:38:ntp:/:/bin/false" >> etc/passwd
fi
if grep "^ntp::" etc/group 1> /dev/null 2> /dev/null ; then
  true
else
  echo "ntp::38:ntp" >> etc/group
fi
if grep "^ntp:" etc/shadow 1> /dev/null 2> /dev/null ; then
  true
else
  echo "ntp:*:9797:0:::::" >> etc/shadow
fi
EOF

	_chfix
	_chgrp_bin
}
