#!/bin/ksh -p
#
# ident "@(#)utrelease.ksh	1.8	12/03/05 Oracle"
#
# Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
#
PATH=/usr/bin:/bin:/usr/sbin:/sbin
export PATH

UTPRODINFO=/opt/SUNWut/lib/utprodinfo
FWPKG=SUNWutdfw

OPTSTR="PR"
PROGRAM_ID="$(basename $0)"
print_product_name=false
print_product_rel=false
no_options=true

Usage() {
    cat 1>&2 <<-ENDIT
	Usage: $PROGRAM_ID
	         Prints Sun Ray Software Product Name and Release Number
	ENDIT

    exit 1
}

# replace the _BN from utprodinfo output to .BN
FormatFWVersion() {
    rel_ver="$(echo $1 |sed 's/_/./')"
    print $rel_ver 
}

while getopts $OPTSTR OPT
do 
    case $OPT in 
        P)   print_product_name=true; no_options=false;;
	R)   print_product_rel=true; no_options=false;; 
	# anything else is an illegal option - print Usage
	*)	Usage;;
    esac 
done 

if  $no_options; then
    echo "Sun Ray Software 5.4.0.0.44"

    if $UTPRODINFO -t installed $FWPKG; then
	    VER=$($UTPRODINFO -p $FWPKG VERSION)  
	    echo "Sun Ray Operating Software $(FormatFWVersion $VER)"
    else
	    echo "Sun Ray Operating Software is not installed"
    fi
else 
    if $print_product_name; then
	echo "Sun Ray Software"
    fi
    if $print_product_rel; then
	echo "5.4.0.0.44"
    fi
fi

exit 0
