Index: branches/releng-10/nanobsd/tools/common.inc.sh
===================================================================
--- branches/releng-10/nanobsd/tools/common.inc.sh	(revision 13483)
+++ branches/releng-10/nanobsd/tools/common.inc.sh	(revision 13483)
@@ -0,0 +1,88 @@
+# Make sure to only load this file ones, even if sourced from multiple
+# locations, preventing weird and wonderfull errors of relative paths.
+if [ -n "$PACKAGE_BUILD_INC_SH" ]; then
+  return
+fi
+PACKAGE_BUILD_INC_SH=true
+
+# Used to store profile data
+TIME_FILE=$(dirname $0)/eta-times.txt
+
+p_list () {
+echo "$*" | sed -e 's/ /|## /g' -e 's/^/## /g'
+}
+
+p_info () {
+  echo "$*" | tr '|' '\n' | sed 's/^/# /'
+}
+
+p_warn () {
+  echo "$*" | tr '|' '\n' | sed 's/^/#WARN: /'
+}
+
+p_err () {
+  echo "$*" | tr '|' '\n' | sed 's/^/#ERR: /'
+}
+
+p_sleep() {
+  SLEEP=${1-5}
+  while [ "${SLEEP}" -gt 0 ]; do
+    printf '.'
+    sleep 1
+    SLEEP=`expr ${SLEEP} - 1`
+  done
+  printf '\n'
+}
+
+# Print estimation on how long it normally if going to take
+f_time() {
+  COMMAND="$*"
+  ETA_TIME=` grep "${COMMAND}$" ${TIME_FILE} 2>/dev/null | awk '{print $1}'`
+  if [ -z "${ETA_TIME}" ]; then
+    ETA_TIME="NaN"
+  fi
+  
+  p_info Last run of "'${COMMAND}'" took ${ETA_TIME}
+  p_info Start time: `date`
+  
+  # Execute command
+  START_TIME=`date "+%s"`
+  $COMMAND
+  RETVAL=$?
+  STOP_TIME=`date "+%s"`
+  
+  p_info End time: `date`
+  # Calculate time it took
+  TOTAL_TIME=`expr ${STOP_TIME} - ${START_TIME}`
+  HUMAN_FMT=`date -ur ${TOTAL_TIME} "+%H:%M:%S"`
+  
+  # Store new time if command is succesfull
+  if [ "${RETVAL}" -eq 0 ]; then
+    grep -v "${COMMAND}$" ${TIME_FILE} > ${TIME_FILE}.tmp 2>/dev/null
+    echo "${HUMAN_FMT} ${COMMAND}" >> ${TIME_FILE}.tmp
+    mv ${TIME_FILE}.tmp ${TIME_FILE}
+  fi
+  
+  # Return the command it's output
+  return ${RETVAL}
+}
+
+f_check_root() {
+  # No Root, no fun
+  if [ `id -u` -ne 0 ]; then
+  	print_err Root only
+  	exit 1
+  fi
+}
+
+# Find object directory 
+BASEDIR=`dirname $0`
+
+# Load the NanoBSD Configuration entries 
+NANO_CFG_FILE="${BASEDIR}/../cfg/nanobsd.wleiden"
+customize_cmd() { return; }
+late_customize_cmd() { return; }
+. $NANO_CFG_FILE
+
+OBJDIR="/usr/obj/nanobsd.${NANO_NAME}"
+
Index: branches/releng-10/nanobsd/tools/package-build.inc.sh
===================================================================
--- branches/releng-10/nanobsd/tools/package-build.inc.sh	(revision 13414)
+++ 	(revision )
@@ -1,88 +1,0 @@
-# Make sure to only load this file ones, even if sourced from multiple
-# locations, preventing weird and wonderfull errors of relative paths.
-if [ -n "$PACKAGE_BUILD_INC_SH" ]; then
-  return
-fi
-PACKAGE_BUILD_INC_SH=true
-
-# Used to store profile data
-TIME_FILE=$(dirname $0)/eta-times.txt
-
-p_list () {
-echo "$*" | sed -e 's/ /|## /g' -e 's/^/## /g'
-}
-
-p_info () {
-  echo "$*" | tr '|' '\n' | sed 's/^/# /'
-}
-
-p_warn () {
-  echo "$*" | tr '|' '\n' | sed 's/^/#WARN: /'
-}
-
-p_err () {
-  echo "$*" | tr '|' '\n' | sed 's/^/#ERR: /'
-}
-
-p_sleep() {
-  SLEEP=${1-5}
-  while [ "${SLEEP}" -gt 0 ]; do
-    printf '.'
-    sleep 1
-    SLEEP=`expr ${SLEEP} - 1`
-  done
-  printf '\n'
-}
-
-# Print estimation on how long it normally if going to take
-f_time() {
-  COMMAND="$*"
-  ETA_TIME=` grep "${COMMAND}$" ${TIME_FILE} 2>/dev/null | awk '{print $1}'`
-  if [ -z "${ETA_TIME}" ]; then
-    ETA_TIME="NaN"
-  fi
-  
-  p_info Last run of "'${COMMAND}'" took ${ETA_TIME}
-  p_info Start time: `date`
-  
-  # Execute command
-  START_TIME=`date "+%s"`
-  $COMMAND
-  RETVAL=$?
-  STOP_TIME=`date "+%s"`
-  
-  p_info End time: `date`
-  # Calculate time it took
-  TOTAL_TIME=`expr ${STOP_TIME} - ${START_TIME}`
-  HUMAN_FMT=`date -ur ${TOTAL_TIME} "+%H:%M:%S"`
-  
-  # Store new time if command is succesfull
-  if [ "${RETVAL}" -eq 0 ]; then
-    grep -v "${COMMAND}$" ${TIME_FILE} > ${TIME_FILE}.tmp 2>/dev/null
-    echo "${HUMAN_FMT} ${COMMAND}" >> ${TIME_FILE}.tmp
-    mv ${TIME_FILE}.tmp ${TIME_FILE}
-  fi
-  
-  # Return the command it's output
-  return ${RETVAL}
-}
-
-f_check_root() {
-  # No Root, no fun
-  if [ `id -u` -ne 0 ]; then
-  	print_err Root only
-  	exit 1
-  fi
-}
-
-# Find object directory 
-BASEDIR=`dirname $0`
-
-# Load the NanoBSD Configuration entries 
-NANO_CFG_FILE="${BASEDIR}/../cfg/nanobsd.wleiden"
-customize_cmd() { return; }
-late_customize_cmd() { return; }
-. $NANO_CFG_FILE
-
-OBJDIR="/usr/obj/nanobsd.${NANO_NAME}"
-
Index: branches/releng-10/nanobsd/tools/package-build.sh
===================================================================
--- branches/releng-10/nanobsd/tools/package-build.sh	(revision 13414)
+++ branches/releng-10/nanobsd/tools/package-build.sh	(revision 13483)
@@ -1,108 +1,55 @@
 #!/bin/sh
-# Install all required packages
 #
-# XXX: Welcome to port hell, if /usr/ports has been updated, you actually want
-# to delete all installed packages and start over again, hence why people used
-# to run this stuff in jails, etc.
-#
-# TODO: Poudriere is mature and the way to go for these days:
-#     https://www.freebsd.org/doc/handbook/ports-poudriere.html
+# Compile listing of required packages using poudriere and friends
 #
 # Rick van der Zwet <rick@wirelessleiden.nl>
 #
 
-. `dirname $0`/package-build.inc.sh
+. `dirname $0`/common.inc.sh
 
-DEBUG=${DEBUG:-'0'}
+cfg_dir=`dirname $0`/../cfg
+poudriere_pkglist_file=${cfg_dir}/wlpkgbuild10_2-default-node-pkglist
 
-# Find listing of packages to build
-PKG_TO_BUILD=${PKG_TO_BUILD:-${PACKAGE_LIST}}
 
-# make options, for package building
-LOGDIR=`mktemp -d /tmp/$(basename $0 .sh)-$(date '+%Y%m%d-%H:%M:%S')X`
+packages_initenv() {
+	config_dir=`dirname $0`
 
-p_info Log directory ${LOGDIR}
-p_info Make arguments are:
-p_info `p_list ${PKG_MAKE_ARGS}`
-p_info Make configuration is:
-echo "${PKG_MAKE_CONF}" | sed 's/^/## /'
+	# Install required deamons
+	pkg install poudriere dialog4ports portshaker
 
-# HACK: install our own ports _inside_ the normal ports dir
-cp -fR $WL_PORTSDIR/* $PORTSDIR || exit 1
+	# Setup poudriere build environment
+	poudriere jail -c -j wlpkgbuild10_2 -v 10.2-RELEASE -a i386
 
-# Cleanup of old packages
-if [ -d "${NANO_PACKAGE_DIR}" ]; then
-	p_warn "Deleted all (old) packages at ${NANO_PACKAGE_DIR}"
-	rm -R ${NANO_PACKAGE_DIR}/*
+	# Setup portshaker
+	cp ${config_dir}/portshaker.conf /usr/local/etc/
+	cp ${config_dir}/portshaker.d/* /usr/local/etc/portshaker.d
+
+	# Update ports
+	portshaker -U
+	portshaker -M
+
+	# Setup poudriere ports environment
+	poudriere ports -c -F -f none -p default -M /usr/local/poudriere/ports/default
+
+	# Build options
+	poudriere options -j wlpkgbuild10_2 -p default -z node -f ${poudriere_pkglist_file}
+}
+
+
+package_build() {
+	poudriere bulk -j wlpkgbuild10_2 -p default -z node -f ${poudriere_pkglist_file}
+}
+
+# Make package list
+. $cfg_dir/nanobsd.wleiden
+echo $PACKAGE_LIST | tr " " "\n" > ${poudriere_pkglist_file}
+
+
+if [ "x$1" = "xinitenv" ]; then
+	packages_initenv
+elif [ "x$1" = "xbuild" ]; then
+	package_build
+else
+	echo "Usage $0 <initenv|build>"
+	exit 128
 fi
-p_info Created target dir ${NANO_PACKAGE_DIR}
-mkdir -p ${NANO_PACKAGE_DIR}
-
-# Build required packages
-MAKE_CONF=`mktemp -t $(basename $0)`
-echo "${PKG_MAKE_CONF}" > $MAKE_CONF
-MAKE="make __MAKE_CONF=$MAKE_CONF ${PKG_MAKE_ARGS}"
-BUILD_LIST=''
-set `echo ${PKG_TO_BUILD} | xargs -n1 -I% echo $PORTSDIR/%`
-while [ "$1" ]; do
-  PACKAGE=$1; shift
-  BUILD_LIST="${BUILD_LIST} ${PACKAGE}"
-
-  # Build new one
-  LOGFILE="$LOGDIR/build_`echo $PACKAGE | tr '/' '_'`.log"
-  echo ""
-  p_info Packaging $PACKAGE
-  cd $PACKAGE || exit 1
-
-  # Check for build dependencies
-  BUILDDEP_PKG=`${MAKE} build-depends-list | awk -F: '{print $2}'`
-  if [ -n "${BUILDDEP_PKG}" ]; then
-	  p_info Build dependencies needed are:
-          p_info `p_list ${BUILDDEP_PKG}`
-  fi
-
-  # Check for run dependencies
-  PKGDEP_PKGS=`${MAKE} package-depends-list | awk '{print $2}'`
-  if [ -n "${PKGDEP_PKGS}" ]; then
-	  p_info Package dependencies also packaged are:
-	  p_info `p_list ${PKGDEP_PKGS}`
-  fi
-
-  PKGNAME=`${MAKE} extract-message | awk '{print $NF}'`
-  PKGBUILDLOG=/tmp/build.$$.`basename $PACKAGE`.log
-  p_info Packaging $PACKAGE ... details at $PKGBUILDLOG
-  ${MAKE} PACKAGES=/root/nanobsd/pkg clean package do-package 1>>$PKGBUILDLOG 2>>$PKGBUILDLOG
-  if [ $? -ne 0 ]; then
-    p_err "Failed to create $PKGNAME"
-    exit 1
-  fi
-
-  p_info Checking dependencies
-  for PKG in $PKGDEP_PKGS; do
-     echo "${BUILD_LIST}" | grep -q "$PKG"
-     if [ $? -eq 0 ]; then
-       # Already packaged
-       p_info ${PKG} Already packaged
-     else
-       echo $@  | grep -q "${PKG}"
-       if [ $? -eq 0 ]; then
-          p_info ${PKG} Already planned
-       else
-          set $@ ${PKG}
-       fi
-     fi
-  done
-  p_info Packaging $PACKAGE succesfull
-done
-  
-p_info `echo ${BUILD_LIST} | wc -w` packages build succesfully
-
-if [ ${DEBUG} -eq 0 ]; then
-  rm -R ${LOGDIR}
-else
-  p_info Debugging enabled ${LOGDIR} saved
-fi
-
-# House keeping
-rm $MAKE_CONF
-
Index: branches/releng-10/nanobsd/tools/portshaker.conf
===================================================================
--- branches/releng-10/nanobsd/tools/portshaker.conf	(revision 13483)
+++ branches/releng-10/nanobsd/tools/portshaker.conf	(revision 13483)
@@ -0,0 +1,16 @@
+# vim:set syntax=sh:
+# $Id$
+
+#---[ Base directory for mirrored Ports Trees ]---
+mirror_base_dir="/var/cache/portshaker"
+
+#---[ Directories where to merge ports ]---
+ports_trees="default"
+
+use_zfs="no"
+poudriere_ports_mountpoint="/usr/local/poudriere/ports"
+default_poudriere_tree="default"
+default_merge_from="freebsd wlrepo"
+
+
+
Index: branches/releng-10/nanobsd/tools/portshaker.d/freebsd
===================================================================
--- branches/releng-10/nanobsd/tools/portshaker.d/freebsd	(revision 13483)
+++ branches/releng-10/nanobsd/tools/portshaker.d/freebsd	(revision 13483)
@@ -0,0 +1,8 @@
+#!/bin/sh
+. /usr/local/share/portshaker/portshaker.subr
+SVN_FLAGS="--quiet"
+
+method="svn"
+svn_checkout_path="svn://svn0.us-west.freebsd.org/ports/head"
+
+run_portshaker_command $*
Index: branches/releng-10/nanobsd/tools/portshaker.d/wlrepo
===================================================================
--- branches/releng-10/nanobsd/tools/portshaker.d/wlrepo	(revision 13483)
+++ branches/releng-10/nanobsd/tools/portshaker.d/wlrepo	(revision 13483)
@@ -0,0 +1,8 @@
+#!/bin/sh
+. /usr/local/share/portshaker/portshaker.subr
+SVN_FLAGS="--quiet"
+
+method="svn"
+svn_checkout_path="https://svn.wirelessleiden.nl/svn/code/hybrid/branches/releng-10/nanobsd/ports"
+
+run_portshaker_command $*
Index: branches/releng-10/nanobsd/tools/write-image.sh
===================================================================
--- branches/releng-10/nanobsd/tools/write-image.sh	(revision 13414)
+++ branches/releng-10/nanobsd/tools/write-image.sh	(revision 13483)
@@ -2,5 +2,5 @@
 # Wrapper allowing to write image to card writer
 
-. $(dirname $0)/package-build.inc.sh
+. $(dirname $0)/common.inc.sh
 
 BASEDIR=`dirname $0`
