#!/bin/bash

# shellcheck shell=sh
# shellcheck disable=SC2034 
# shellcheck disable=SC2059
# shellcheck disable=SC1091
# shellcheck disable=SC1090

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

if [ -z "$AUXILIUM_ARG_sh_completion" ]; then
	fo_init
fi

# shellcheck disable=SC2154
phy=$(jq -r '.["PD LIST"][]|select(.DID=='"${AUXILIUM_ARG_did}"')["EID:Slt"]' "${FO_CACHE_FILE_STORCLI}")
es="/e$(echo "${phy}"|awk -F':' '{print $1"/s"$2}')"
${STORCLI} /c0"${es}" set good force  2>/dev/null || true
${STORCLI} /c0 add vd r0 drives="${phy}" direct wb ra  2>/dev/null

