#!/bin/bash

set -e
#set -x

if [ $(id -u) -ne 0 ]; then
	echo "$0 needs root: please use sudo."
	exit 1
fi

# Source Auxilium (args parser)
. /usr/share/auxilium/auxilium.sh

auxilium_init $(basename $0) -m 'Configure RAID 0 for a device'

auxilium_add did -t positional -m 'Disk ID '


if [ -f "/usr/share/ferreus-orbit/common.sh" ]; then
	. "/usr/share/ferreus-orbit/common.sh"
elif [ -f "share/common.sh" ] ; then
	. "share/common.sh"
else
	. "../share/common.sh"
fi

auxilium_parse "$@"

fo_lock

readonly phy=$(${STORCLI} /call show all J| jq -r '.["Controllers"][]["Response Data"]["PD LIST"][]|select(.DID=='${AUXILIUM_ARG_did}')["EID:Slt"]')

echo "Setting up RAID for device ${AUXILIUM_ARG_did} (EID:Slt=${phy})..."

${STORCLI} /c0/vall delete preservedcache force ||true
${STORCLI} /c0 add vd r0 drives=${phy} direct wb ra

