#!/bin/sh


# toolkit_functions - misc functions needed by toolkit scripts
# you can add your own functions here and source them into your custom scripts


read_break () {
        echo "hit <enter> to continue OR a <non-blank char>+<enter> to break to bash"
        read reply
        if [ ! -z ${reply} ]; then
                exec /bin/bash
        fi
}


get_serverid () {

TEMP=$(cat ${1} | grep SystemId | awk -F'<' '{print $2}' | awk -F'>' '{print $2}')

SERVERID=$(echo ${TEMP} | sed 's/\(.*\)E11\(.*\)/\2/g')

}


get_bootdevnode () {

echo "get_bootdevnode: 1 ="${1}

BOOTDEVNODE=$(cat ${1} | grep DevNode | awk -F'<' '{print $2}' | awk -F'>' '{print $2}')

}

make_sssd () {
	echo
	ARRAY=

	NODE=$(echo $1 | awk -F '/' '{print $NF}')
	## another way to do the above...far more cryptic...lol
	# NODE=${1##/*/}
	# the translation of the above goes like this
	# using $1, find the longest match for "/*/", delete the match, and return the rest

	echo "NODE="${NODE}

	if [ ${NODE/c[0-9]d[0-9]/array} == "array" ]; then
		ARRAY=1
	else
		ARRAY=0
	fi

	echo "ARRAY="${ARRAY}

	# based upon the array condition, we need to link the sssd's to the device nodes
	if [ ${ARRAY} == "1" ]; then

		#PREFIX=${1}
		ln -s ${1} /dev/sssd
		ln -s ${1}p1 /dev/sssd1
		ln -s ${1}p2 /dev/sssd2
		ln -s ${1}p3 /dev/sssd3
		ln -s ${1}p4 /dev/sssd4
	else
		ln -s ${1} /dev/sssd
		ln -s ${1}1 /dev/sssd1
		ln -s ${1}2 /dev/sssd2
		ln -s ${1}3 /dev/sssd3
		ln -s ${1}4 /dev/sssd4

	fi	
}
