#!/bin/bash
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
fwpref=${rvid_fwrev%%???}
fwver=${rvid_fwrev##????}
fwmaj=${fwver%%?}
if [ -z "$fwmaj" ]; then
    echo "Unable to recognize AMM firmware revision"
    exit 1
fi
mkdir -p /tmp/xcat
if [ ! -f /tmp/xcat/$rvid_server.remotekvm.jar ]; then
    wget --no-check-certificate -O /tmp/xcat/$rvid_server.remotekvm.jar http://$rvid_server/private/remotekvm.jar >& /dev/null
fi
if [ $fwpref == 'BPET' ]; then
    if [[ "0x$fwmaj" -ge "0x46" ]]; then
        java -jar /tmp/xcat/$rvid_server.remotekvm.jar -s $rvid_server -r $rvid_authtoken -b $rvid_slot -B -R >& /dev/null
    elif [ $fwmaj -ge 42 ]; then
        echo "Unable to securely support $rvid_fwrev in an adequately secure manner, please upgrade to BPET46C or better"
        exit 1
        java -jar /tmp/xcat/$rvid_server.remotekvm.jar $rvid_server -rbs $rvid_authtoken -ba $rvid_ba -port $rvid_port >& /dev/null
    else
        echo "Unknown method for firmware $rvid_fwrev, ensure it is at least BPET42R";
    fi
else
    echo "Unknown semantics for $fwpref, trying a particular way, may not work."
   java -jar /tmp/xcat/$rvid_server.remotekvm.jar $rvid_server -rbs $rvid_authtoken -ba $rvid_ba -b $rvid_slot >& /dev/null
fi

rm /tmp/xcat/$rvid_server.remotekvm.jar
