#!/bin/sh
#
# mount nfs shares
#
# runlevels: geexbox, debug, configure

IFS='
'

if test -f /etc/nfs -a -f /etc/network; then
  echo "### Mounting NFS shares ###"
  . /etc/network
  (
    while [ ! -f /var/ifup ]; do
      sleep 1
    done 
    while true; do
      for MOUNTS in `grep -v "^#" /etc/nfs | grep -v "^$"`; do
        SRV="`echo $MOUNTS | sed 's/[ ]*\([^ ]*\)[ ]*.*/\1/'`"
        DIR="`echo $MOUNTS | sed 's/[ ]*[^ ]*[ ]*\([^ ]*\)/\1/'`"
        if [ ! -e "/mnt/nfs/$DIR" ]; then
          mkdir -p "/mnt/nfs/$DIR"
          mount -t nfs -o ro,nolock "$SRV" "/mnt/nfs/$DIR" >/dev/null 2>&1 || rmdir -p "/mnt/nfs/$DIR"
        fi
      done
      [ -z "$NET_RESCAN_DELAY" -o $NET_RESCAN_DELAY -le 0 ] && break
      sleep $NET_RESCAN_DELAY
    done
  )&
fi

exit 0
