#!/bin/sh
# 
if [ "$1" = "prereqs" ]; then
  exit 0
fi

quiet=n

. /scripts/functions

# if break=nbd_filesystem STOP here
maybe_break nbd_filesystem


. /conf/tcos.conf
. /conf/tcos-run-functions


TCOS_ENABLE_NBD=$(read_cmdline_var "nbd" "0")

if [ "$TCOS_ENABLE_NBD" != "0" ]; then
  
  log_begin_msg "Mounting remote squashfs with NBD"

    NBD_PORT=$(read_cmdline_var "nbdport" "2000")

    # load 1 nbd devices
    modprobe nbd nbds_max=1

    # wait for device
    while [ ! -e /dev/nbd0 ]; do
      sleep 1
    done

    nbd-client tcos-server $NBD_PORT /dev/nbd0
    sleep 1

    mount /dev/nbd0 /usr

  log_end_msg $?

fi

exit 0
