$NetBSD$

--- ../FreeBSD/lib/tinderlib.sh	2011-10-16 00:52:55.000000000 +0000
+++ lib/tinderlib.sh
@@ -50,10 +50,10 @@ tinderLoc () {
 			fi
 			;;
     "builddata")	echo "${pb}/builds/${what}";;
-    "buildports")	echo "$(tinderLoc buildroot ${what})/a/ports";;
+    "buildports")	echo "$(tinderLoc buildroot ${what})/a/pkgsrc";;
     "buildsrc")		echo "$(tinderLoc buildroot ${what})/usr/src";;
     "buildccache")	echo "$(tinderLoc buildroot ${what})/ccache";;
-    "buildoptions")	echo "$(tinderLoc buildroot ${what})/var/db/ports";;
+    "buildoptions")	echo "$(tinderLoc buildroot ${what})/var/db/options";;
     "builddistcache")	echo "$(tinderLoc buildroot ${what})/distcache";;
     "builderrors")	echo "${pb}/errors/${what}";;
     "buildlogs")	echo "${pb}/logs/${what}";;
@@ -197,7 +197,7 @@ cleanupMounts () {
 	    echo "cleanupMounts: ${_type}: missing portstree"
 	    return 1
 	fi
-	_dstloc=${_dstloc:-$(tinderLoc portstree ${_portstree})/ports}
+	_dstloc=${_dstloc:-$(tinderLoc portstree ${_portstree})/pkgsrc}
 	;;
 
     *)
@@ -227,7 +227,6 @@ requestMount () {
     _type=""
     _srcloc=""
     _dstloc=""
-    _nullfs=0
     _readonly=0
     _build=""
     _jail=""
@@ -242,7 +241,6 @@ requestMount () {
 	b)	_build=${OPTARG};;
 	d)	_dstloc=${OPTARG};;
 	j)	_jail=${OPTARG};;
-	n)	_nullfs=1;;
 	p)	_portstree=${OPTARG};;
 	r)	_readonly=1;;
 	s)	_srcloc=${OPTARG};;
@@ -267,7 +265,7 @@ requestMount () {
 	if [ -z "${_srcloc}" ] ; then
 	    _srcloc=$(${tc} getPortsMount -p ${_portstree})
 	    if [ -z "${_srcloc}" ] ; then
-		_srcloc=${_srcloc:=$(tinderLoc portstree ${_portstree})/ports}
+		_srcloc=${_srcloc:=$(tinderLoc portstree ${_portstree})/pkgsrc}
 	    else
 		_fqsrcloc=1
 	    fi
@@ -332,7 +330,7 @@ requestMount () {
 	    echo "requestMount: ${_type}: missing portstree"
 	    return 1
 	fi
-	_dstloc=${_dstloc:-$(tinderLoc portstree ${_portstree})/ports}
+	_dstloc=${_dstloc:-$(tinderLoc portstree ${_portstree})/pkgsrc}
 	_srcloc=${_srcloc:-$(${tc} getPortsMount -p ${_portstree})}
 	_fqsrcloc=1
 	;;
@@ -355,64 +353,31 @@ requestMount () {
     fi
 
     # is the filesystem already mounted?
-    fsys=$(df ${_dstloc} 2>/dev/null | awk '{a=$1}  END {print a}')
-    mtpt=$(df ${_dstloc} 2>/dev/null | awk '{a=$NF} END {print a}')
+    # We can't use df $_dstloc directly because HAMMER returns the
+    # PFS address rather than the source location like UFS does
+    fsys=$(df | grep '^${_dstloc}' | awk '{a=$1}  END {print a}')
+    mtpt=$(df | grep '^${_dstloc}' | awk '{a=$NF} END {print a}')
 
     if [ "${fsys}" = "${_srcloc}" -a "${mtpt}" = "${_dstloc}" ]; then
 	return 0
     fi
 
-    # is _nullfs mount specified?
-    if [ ${_nullfs} -eq 1 -a ${_fqsrcloc} -ne 1 ] ; then
-	_options="-t nullfs"
-    else
-	# it probably has to be a nfs mount then
-	# lets check what kind of _srcloc we have. If it is allready in
-	# a nfs format, we don't need to adjust anything
-	case ${_srcloc} in
-
-	[a-zA-Z0-9\.-_]*:/*)
-		_options="-o nfsv3,intr,tcp"
-		;;
-
-	*)
-		if [ ${_fqsrcloc} -eq 1 ] ; then
-		    # some _srcloc's are full qualified sources, means
-		    # don't try to detect sth. or fallback to localhost.
-		    # The user wants exactly what he specified as _srcloc
-		    # don't modify anything. If it's not a nfs mount, it has
-		    # to be a nullfs mount.
-		    _options="-t nullfs"
-		else
-		    _options="-o nfsv3,intr,tcp"
-
-		    # find out the filesystem the requested source is in
-		    fsys=$(df ${_srcloc} | awk '{a=$1}  END {print a}')
-		    mtpt=$(df ${_srcloc} | awk '{a=$NF} END {print a}')
-		    # determine if the filesystem the requested source
-		    # is a nfs mount, or a local filesystem
-
-		    case ${fsys} in
-
-		    [a-zA-Z0-9\.-_]*:/*)
-			# maybe our destination is a subdirectory of the
-			# mountpoint and not the mountpoint itself.
-			# if that is the case, add the subdir to the mountpoint
-			_srcloc="${fsys}/$(echo $_srcloc | \
-					sed 's|'${mtpt}'||')"
-			;;
-
-		    *)
-			# not a nfs mount, nullfs not specified, so
-			# mount it as nfs from localhost
-			_srcloc="localhost:/${_srcloc}"
-			;;
-
-		    esac
-
-		fi
-		;;
-	esac
+    # The default mounting option is nullfs for DragonFly.  This is required
+    # for HAMMER filesystems as it's not possible to have NFS mounts directly
+    # there.  For UFS, it's still the preferred option for performance
+    # reasons.  Therefore the only attempt to use NFS is if the mount point
+    # is defined in the database and it's in the NFS server:directory format.
+
+    _options="-t null"
+    if [ ${_fqsrcloc} -eq 1 ]; then
+       case ${_srcloc} in
+
+       [a-zA-Z0-9\.-_]*:/*)
+               _options="-o nfsv3,intr,tcp"
+               ;;
+       *)
+               ;;
+       esac
     fi
 
     if [ ${_readonly} -eq 1 ] ; then
@@ -424,6 +389,7 @@ requestMount () {
 	mkdir -p ${_dstloc}
     fi
 
+    echo "mount ${_options} ${_srcloc} ${_dstloc}"
     mount ${_options} ${_srcloc} ${_dstloc}
     return ${?}
 }
@@ -506,15 +472,16 @@ buildenvNoHost () {
     eval "export __MAKE_CONF=${jailBase}/make.conf" >/dev/null 2>&1
     eval "export LOCALBASE=/nonexistentlocal" >/dev/null 2>&1
     eval "export PKG_DBDIR=/nonexistentdb" >/dev/null 2>&1
-    if [ x"${OPTIONS_ENABLED}" != x"1" ]; then
-        eval "export PORT_DBDIR=/nonexistentportdb" >/dev/null 2>&1
-    else
-	optionsDir=$(tinderLoc options ${build})
-
-	eval "export PORT_DBDIR=${optionsDir}" >/dev/null 2>&1
-    fi
     eval "export LINUXBASE=/nonexistentlinux" >/dev/null 2>&1
     eval "unset DISPLAY" >/dev/null 2>&1
+
+    # When the tinderd is launched by the rc system at boot time (normal)
+    # it doesn't have the /usr/pkg/bin path set.  FreeBSD has their make
+    # in the path that rc scripts can access, but this is not true for
+    # pkgsrc bmake on any system other than NetBSD.  Let's add it to
+    # path while we're in the subshell.
+
+    eval "export PATH=${PATH}:/usr/pkg/bin" >/dev/null 2>&1
 }
 
 getDbDriver () {
@@ -629,7 +596,7 @@ checkPreReqs () {
     missing=""
 
     for r in ${reqs} ; do
-	if [ -z $(pkg_info -Q -O ${r}) ]; then
+	if [ -z $(pkg_info -e ${r}) ]; then
 	    missing="${missing} ${r}"
 	    error=1
 	fi
