#!/bin/bash

for i in /mnt/md* ; do
	if [ -d $i ]; then
		for s in $i/spare-loop* ; do
			if [ -f $s ]; then
				echo setup iscsi lun
				loopdev=`echo $s | awk -F '-' '{print $2}'`
				losetup /dev/$loopdev $s
			fi
		done
	fi
done

# mount iso image file
ISOMOUNT=`sqlite3 /etc/base/nasdb "select * from share where type='ISO'"`
for i in $ISOMOUNT
do
        echo $i
        mntfile=`echo $i | awk -F '|' '{print $10}'`
        mntpath=`echo $i | awk -F '|' '{print $4}'`
        mount $mntfile $mntpath
        if [ $? == 0 ]; then
                echo mount $mntfile to $mntpath file success
        else
                echo mount $mntfile to $mntpath file failed
        fi
done
