#!/bin/bash
#
# bootdisk

PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:.


iface=$(hintget vdisk_ethlist | cut -d, -f1)
[ -z "$iface" ] && iface="eth0"

start() {

## bootio
	ps -A |grep -q bootio && killall -9 bootio >/dev/null
	systemdisk_no=15
        for image_disk in $(hintget image_list | tr ',' ' ')
        do
		if [ "$image_disk" == "USER_SELECT" ]
		then
			continue	
		fi	
		ramdisk=$(hintget image_${image_disk}_ramdisk)
		if [ "$ramdisk" == "on" ]
		then
			system_path=/mnt/system/${image_disk}/image
		else
			system_path=$(hintget $(hintget image_${image_disk}_dir)_dir)/${image_disk}/image
		fi
		if [ -f "$system_path" ]
		then
			/usr/local/bin/bootio 0 2 $iface $system_path $[$systemdisk_no*256] &
#			echo "image: $image_disk ======>>> path:$system_path not found"
		fi
		systemdisk_no=$[$systemdisk_no+1]
        done
	if [ -f /proc/vDisk ]
	then

        disk_status=$(get_vdisk_status 0 0)
        if [ "$disk_status" == "on" ]
        then
                image_disk=$(hintget superip | cut -d# -f3)
                system_dir=$(hintget $(hintget image_${image_disk}_dir)_dir)/${image_disk}
                /usr/local/bin/bootio 0 0 $iface ${system_dir}/image $[24*256] &
        fi
		
     fi
	
}

stop() {
	ps -A |grep -q bootio && killall -9 bootio >/dev/null
}

case $1 in 
   start)
	start
	;;
   stop)
	stop
	;;
   restart)
	stop
	start
	;;
   *)
	echo "bootdisk start|stop|restart|"
esac

