#!/usr/local/bin/cbsd
#v12.0.4
MYARG="path"
MYOPTARG=""
MYDESC="Show image type: iso or vhd or .."
CBSDMODULE="sys"
ADDHELP=""

. ${subrdir}/nc.subr

. ${cbsdinit}

. ${system}

[ ! -r "${path}" ] && err 1 "${N1_COLOR}No such file: ${N2_COLOR}${path}${N0_COLOR}"

iso_type="ISO 9660 CD-ROM filesystem data|DOS/MBR boot sector"

res=$( ${miscdir}/fmagic -file=${path} )

is_iso=0
is_hdd=0

echo "${res}" | ${GREP_CMD} -q "extended partition" 2>/dev/null

if [ $? -eq 0 ]; then
	is_hdd=1
else
	OIFS="${IFS}"
	IFS="|"
	for i in ${iso_type}; do
		IFS="${OIFS}"
		strlen=$( strlen "${i}" )
		type_path=$( substr --pos=0 --len=${strlen} --str="${res}" )
		if [ "${type_path}" = "${i}" ]; then
			is_iso=1
			break
		fi
	done
fi

if [ ${is_iso} -eq 1 ]; then
	printf "iso"
else
	printf "hdd"
fi

exit 0

