Index: trunk/nanobsd/files/tools/nsdc-rebuild.sh
===================================================================
--- trunk/nanobsd/files/tools/nsdc-rebuild.sh	(revision 10136)
+++ trunk/nanobsd/files/tools/nsdc-rebuild.sh	(revision 10136)
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+if [ ! -f /var/db/nsd/ixfr.db ]; then
+  nsdc rebuild
+  nsdc start
+fi
Index: trunk/nanobsd/files/tools/update-file
===================================================================
--- trunk/nanobsd/files/tools/update-file	(revision 10136)
+++ trunk/nanobsd/files/tools/update-file	(revision 10136)
@@ -0,0 +1,60 @@
+#!/bin/sh
+#
+# Update an single file (content via stdin) on the flash disk if the md5 does
+# not match. This script tries to be on the safe side by checking md5 at
+# various stages.
+#
+# TODO: Maybe rsync is also able to perform the mount and umount before and
+# after, this will eliminate all the hacking with md5 checks.
+#
+# Rick van der Zwet <info@rickvanderzwet.nl>
+#
+
+if [ -z "$1" ]; then
+  echo "Usage: $0 <filepath> [<md5sum> [<file mode bits> [<file ownership>]]]" 1>&2
+  exit 128
+fi
+
+FILE=$1
+NEW_MD5=${2:-""}
+MODE_BITS=${3:-""}
+OWNERSHIP=${4:-""}
+
+if [ ! -f "$FILE" ]; then
+  echo "# ERROR: File $FILE does not exists" 1>&2
+  exit 1
+fi
+
+# First try to transfer file to local system
+# this restricts the filesize to the maximum size of the /tmp system
+TMPFILE=`mktemp -t $(basename $0)` || exit 1
+cat > $TMPFILE || exit 1
+TMP_MD5="`md5 -q $TMPFILE`" || exit 1
+
+# Check which md5 to use, the given one or the calculated one
+if [ -n "$NEW_MD5" ]; then
+  TARGET_MD5="$NEW_MD5"
+  if [ "$TMP_MD5" != "$TARGET_MD5" ]; then
+    echo "# ERROR: File transfer failed" 1>&2
+    exit 2
+  fi
+else
+  TARGET_MD5="$TMP_MD5"
+fi
+
+# Actually check whether we need to copy the file 
+CURRENT_MD5=`md5 -q $FILE` || exit 1
+if [ "$CURRENT_MD5" != "$TARGET_MD5" ]; then
+  echo "# INFO: Updating $FILE; old MD5 $CURRENT_MD5"
+  mount -uwo noatime / || exit 1
+  cp -f $TMPFILE $FILE
+  [ -n "$MODE_BITS" ] && chmod $MODE_BITS $FILE
+  [ -n "$OWNERSHIP" ] && chown $OWNERSHIP $FILE
+  mount -ur /
+
+  # Make sure to recheck the md5 alter write to make sure all went ok
+  RECHECK_MD5=`md5 -q $FILE`
+  echo "# INFO: Updated $FILE; new MD5 $RECHECK_MD5"
+else
+  echo "# INFO: File $FILE already has md5 $CURRENT_MD5"
+fi
Index: trunk/nanobsd/files/tools/wl-config
===================================================================
--- trunk/nanobsd/files/tools/wl-config	(revision 10123)
+++ trunk/nanobsd/files/tools/wl-config	(revision 10136)
@@ -1,37 +1,16 @@
 #!/bin/sh
-# Wireless Leiden config-update script for FreeBSD 8.0 (nanobsd)
+# Wireless Leiden proxy config-update script for FreeBSD 8.0 (nanobsd)
 # Based on the 'API' of Jasper
-# Rick van der Zwet
+# Rick van der Zwet ; Richard van Mansom
 # XXX: TODO, some proper error checking for fetch
 
-
-# Slow connection = no connection
-export HTTP_TIMEOUT=3
-
-
-check_access() {
-  # Direct Access - Internal IP 
-  BASEURL="http://172.16.4.46/wleiden/config/"
-  echo "# INFO: Trying to fetch via internal WL $BASEURL"
-  fetch -o /dev/null -q $BASEURL > /dev/null && return
-  echo "# WARN: Fetch via internal $BASEURL failed"
-  
-  # Direct Access - External DNS
-  BASEURL="http://132.229.112.21/wleiden/config/"
-  echo "# INFO: Trying to fetch via external $BASEURL"
-  fetch -o /dev/null -q $BASEURL > /dev/null && return
-  echo "# CRIT: Fetch via external $BASEURL failed"
-
-  exit 1
-}
-check_access
-
+BASEURL="http://132.229.112.21/config/iris/proxy/FreeBSD/8.0-RELEASE/g_list.pl"
 
 # Default config to fetch
-CONFIG=`hostname -s`
+CONFIG=`hostname -s | tr '[A-Z]' '[a-z]'`
 
 # Determine it's statup and running location and some other hints
 # Skip named.conf as it not planned in current release
-FILES="authorized_keys dnsmasq.conf rc.conf.local resolv.conf motd wleiden.yaml"
+FILES="authorized_keys rc.conf.local resolv.conf"
 file_details() {
   case "$1" in 
@@ -40,19 +19,4 @@
      RUNNING_LOC="/etc/dot_ssh/${FILE}"
      FILE_HINT=""
-   ;;
-  'motd')
-     STARTUP_LOC="/cfg/$1"
-     RUNNING_LOC="/etc/$1"
-     FILE_HINT=""
-   ;;
-  'dnsmasq.conf')
-     STARTUP_LOC="/cfg/local/${FILE}"
-     RUNNING_LOC="/etc/local/${FILE}"
-     FILE_HINT="/usr/local/etc/rc.d/dnsmasq restart"
-   ;;
-  'named.conf')
-     STARTUP_LOC="/cfg/namedb/${FILE}"
-     RUNNING_LOC="/etc/namedb/${FILE}"
-     FILE_HINT="/etc/rc.d/named restart"
    ;;
   'rc.conf.local')
@@ -66,9 +30,4 @@
      FILE_HINT=""
    ;;
-   'wleiden.yaml')
-     STARTUP_LOC="/cfg/local/${FILE}"
-     RUNNING_LOC="/etc/local/${FILE}"
-     FILE_HINT=""
-   ;;
   esac
 }
@@ -77,12 +36,12 @@
 	(
 	echo "Usage: $0 [-bn] [-c <config>] [-m <all|startup|testing|running>]"
-	echo "	-b          = batch mode, no user input"
-	echo "	-c <config> = default configuration to fetch"
-	echo "	-n          = do not mount config partition"
-	echo "	-m all      = copy config files to running & config partition [default]"
-	echo "	-m startup  = copy config files to config partition"
-	echo "	-m testing  = do not copy config files"
-	echo "	-m running  = copy config files to running partition"
-	echo "	-m hack     = copy running files to config partition"
+	echo "	-b		batch mode, no user input"
+	echo "	-c <config>   	default configuration to fetch"
+	echo "	-n		do not mount config partition"
+	echo "	-m all    	copy config files to running & config partition [default]"
+	echo "	-m startup	copy config files to config partition"
+	echo "	-m testing    	do not copy config files"
+	echo "	-m running   	copy config files to running partition"
+	echo "	-m hack   	copy  running files to config partition"
 	) 1>&2
 	exit 2
@@ -121,14 +80,14 @@
   
   if [ "${OPT_RUNNING}" -eq 1 ]; then
-    echo "# INFO: Storing new config files in running configuration"
+    echo "INFO: Storing new config files in running configuration"
   fi
   
   if [ "${OPT_STARTUP}" -eq 1 ]; then
-    echo "# INFO: Storing new config files in startup configuration"
+    echo "INFO: Storing new config files in startup configuration"
   fi
   
   if [ "${OPT_HACK}" -eq 1 ]; then
-    echo "# WARN: Copy running configuration to startup configuration"
-    echo "# WARN: Please do mind to document/mention this changes somewhere"
+    echo "WARN: Copy running configuration to startup configuration"
+    echo "WARN: Please do mind to document/mention this changes somewhere"
   fi
 
@@ -148,5 +107,5 @@
   else 
      echo "WARNING: Input '${INPUT}' is not valid, some hints..."
-     grep -i "${INPUT}" ${TMPDIR}/node_list.txt
+     grep "${INPUT}" ${TMPDIR}/node_list.txt
      return 1
   fi  
@@ -197,10 +156,10 @@
 # Copy file, saving some bits if no change needed
 copy_file() {
-  NEWFILE=$1
+  SOURCE=$1
   TARGET=$2
-  diff -I '^# Generated at ' ${TARGET} ${NEWFILE} 2>/dev/null
+  diff -q ${SOURCE} ${TARGET} >/dev/null 2>/dev/null
   if [ $? -ne 0 ]; then
     mkdir -p `dirname ${TARGET}` || exit 1
-    cp ${NEWFILE} ${TARGET} || exit 1
+    cp ${SOURCE} ${TARGET} || exit 1
     return $?
   fi
@@ -241,5 +200,5 @@
     file_details ${FILE}
   
-    echo "# INFO: Working on file: '${FILE}'"
+    echo "INFO: Working on file: '${FILE}'"
     # Copy file boot location
     if [ ${OPT_STARTUP} -eq 1 ]; then
@@ -251,7 +210,7 @@
       copy_file ${FRESH_LOC} ${RUNNING_LOC}
       if [ $? -eq 0 ]; then
-        echo "# INFO: '${FILE}' changed"  
+        echo "INFO: '${FILE}' changed"  
         if [ -n "${FILE_HINT}" ]; then
-          echo "# INFO: For instant activate: ${FILE_HINT}"
+          echo "INFO: For instant activate: ${FILE_HINT}"
           echo ""
         fi
