Index: branches/releng-9.0/nanobsd/tools/image
===================================================================
--- branches/releng-9.0/nanobsd/tools/image	(revision 10593)
+++ branches/releng-9.0/nanobsd/tools/image	(revision 10612)
@@ -22,4 +22,6 @@
 # rebuild                       - Rebuild NanoBSD (aka force rebuilding all)
 # deploy on <node> [and reboot] - Deploy the image on node and reboot if needed
+# ports update 			- Update the packages from ports 
+# ports force rebuild		- Forcefully rebuilding all required packages
 EOF
 }
@@ -110,5 +112,4 @@
 }
 
-
 #
 # Argument parsing
@@ -150,4 +151,26 @@
   fi
   deploy_image
+elif [ "$1" = "ports" ]; then
+  if [ "$2" = "update" ]; then
+    # Fetch the latest details and provide listing of packages to be updated
+    portsnap fetch update || exit 1
+
+    # HACK: install our own ports _inside_ the normal ports dir
+    cp -fR $WL_PORTSDIR/* $PORTSDIR
+
+    # Make sure portmaster is present to update all ports
+    portmaster --version 1>/dev/null 2>/dev/null || make -C /usr/ports/ports-mgmt/portmaster BATCH=yes install clean || exit 1
+
+    # Update via portmaster
+    portmaster --no-confirm --update-if-newer -y -d -G  `echo $PKG_MAKE_ARGS | xargs -n1 echo -m `  $PACKAGE_LIST || exit 1
+
+    . ${BASEDIR}/package-build.sh
+  elif [ "$2" = "force" -a "$3" = "rebuild" ]; then
+    export FORCE_REBUILD=1
+    . ${BASEDIR}/package-build.sh
+  else
+    shift 1
+    echo "Arguments Error - '$*'"; exit 128
+  fi
 else
   echo "Argument Error - '$1'"; exit 128
Index: branches/releng-9.0/nanobsd/tools/package-build.sh
===================================================================
--- branches/releng-9.0/nanobsd/tools/package-build.sh	(revision 10593)
+++ branches/releng-9.0/nanobsd/tools/package-build.sh	(revision 10612)
@@ -1,20 +1,28 @@
 #!/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.
+#
+# Rick van der Zwet <rick@wirelessleiden.nl>
+#
 
-. $(dirname $0)/package-build.inc.sh
+. `dirname $0`/package-build.inc.sh
 
-DEBUG=${DEBUG:-0}
-DEP_CHECK_ONLY=${DEP_CHECK_ONLY:-0}
+DEBUG=${DEBUG:-'0'}
+DEP_CHECK_ONLY=${DEP_CHECK_ONLY:-'0'}
 
 # make options, for package building
-LOGDIR=`mktemp -d "/tmp/$(basename $0 .sh)-$(date +%Y%m%d-%H:%M:%S).X"`
+LOGDIR=`mktemp -d /tmp/$(basename $0 .sh)-$(date '+%Y%m%d-%H:%M:%S')X`
 
 p_info Log directory ${LOGDIR}
 p_info Make options are:
-p_info $(p_list ${PKG_MAKE_ARGS})
+p_info `p_list ${PKG_MAKE_ARGS}`
 
+# HACK: install our own ports _inside_ the normal ports dir
+cp -fR $WL_PORTSDIR/* $PORTSDIR
+
+# Pre-req dependency fixing
 p_info Checking whether there are currently unmet dependencies
 RETVAL=0
@@ -30,5 +38,5 @@
   if [ -n "${PKG_DEP_FAIL}" ]; then
       p_err Unmet dependencies found at $PKG, please fix manually:
-      p_err $(p_list ${PKG_DEP_FAIL})
+      p_err `p_list ${PKG_DEP_FAIL}`
       RETVAL=1
   fi
@@ -45,4 +53,5 @@
 
 
+# Cleanup of old packages
 if [ -d "${NANO_PACKAGE_DIR}" ]; then
 	p_warn "Deleted all (old) packages at ${NANO_PACKAGE_DIR}"
@@ -52,8 +61,8 @@
 mkdir -p ${NANO_PACKAGE_DIR}
 
+
+# Build required packages
 MAKE="make ${PKG_MAKE_ARGS}"
-
 BUILD_LIST=''
-# Build required packages
 set ${PACKAGE_LIST}
 while [ "$1" ]; do
@@ -62,15 +71,14 @@
 
   # Build new one
-  LOGFILE="$LOGDIR/build$(echo $PACKAGE | tr '/' '_').log"
+  LOGFILE="$LOGDIR/build_`echo $PACKAGE | tr '/' '_'`.log"
   echo ""
   p_info Packaging $PACKAGE
-  cd ${PACKAGE}
+  cd $PORTSDIR/$PACKAGE
 
-  
   # 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})
+          p_info `p_list ${BUILDDEP_PKG}`
   fi
 
@@ -79,20 +87,23 @@
   if [ -n "${PKGDEP_PKGS}" ]; then
 	  p_info Package dependencies also packaged are:
-	  p_info $(p_list ${PKGDEP_PKGS})
+	  p_info `p_list ${PKGDEP_PKGS}`
   fi
 
   # Check if package is already installed
   VERSION=`${MAKE} clean generate-plist check-already-installed | awk '/is already/ {print $2}'`
-   if [ -n "${VERSION}" ]; then
+   if [ -n "$FORCE_REBUILD" ]; then
+     p_warn "${PACKAGE} forcefullly rebuilding..."
+     MAKE_OPTION='deinstall reinstall'
+   elif [ "${VERSION}" = "An" ]; then
+     #XXX: Better way to detect whether a package needs updating
+     # An older version of lang/python26 is already installed (python26-2.6.2)
+     p_warn "${PACKAGE} outdated, updating..."
+     p_warn "re-run package-build.sh to check for unmet ones done using:"
+     p_warn "$0"
+     MAKE_OPTION='deinstall reinstall'
+   elif [ -n "${VERSION}" ]; then
      VERSION=`echo ${VERSION} | sed 's/^.*-//g'`
      p_info ${PACKAGE} already installed at ${VERSION}
      MAKE_OPTION=''
-   elif [ "${VERSION}" = "An" ]; then
-     #XXX: Better way to detect whether a package needs updating
-     # An older version of lang/python26 is already installed (python26-2.6.2)
-     p_warn ${PACKAGE} outdated, updating...
-     p_warn re-run package-build.sh to check for unmet ones done using:
-     p_warn $0
-     MAKE_OPTION='deinstall reinstall'
    else
      p_info ${PACKAGE} not installed, installing...
@@ -130,5 +141,5 @@
 done
   
-p_info $(echo ${BUILD_LIST} | wc -w) packages build succesfully
+p_info `echo ${BUILD_LIST} | wc -w` packages build succesfully
 
 if [ ${DEBUG} -eq 0 ]; then
