File: //opt/resolve/scripts/script.checkfirmware
#!/bin/bash
USER=`whoami`
if [ "${USER}" != "root" ]
then
echo "This script must be run as the super-user."
exit 1
fi
UPDATER_BIN="/usr/bin/BlackmagicFirmwareUpdater"
if [ ! -f ${UPDATER_BIN} ]
then
echo "No firmware updater found."
exit 0
fi
STATUS=`${UPDATER_BIN} status | head -n 1 | awk '{print $NF}'`
CARD_NUM=0
if [ "${STATUS}" == "PLEASE_UPDATE" ]
then
XMSG_BIN=/usr/bin/xmessage
DO_REBOOT=0
# Find a temporary file that we can write to
TMP_FILE=/tmp/$$${RANDOM}.tmp
while [ -f ${TMP_FILE} ]
do
TMP_FILE=/tmp/${RANDOM}.tmp
done
echo "The DeckLink firmware needs to be updated." > ${TMP_FILE}
echo "The update process should not be interrupted while it is running." >> ${TMP_FILE}
echo "The system will be rebooted after a successful update." >> ${TMP_FILE}
echo >> ${TMP_FILE}
echo "Please click Ok to proceed with the update." >> ${TMP_FILE}
${XMSG_BIN} -center -buttons "Ok":0,"Cancel":1 -default "Cancel" -file ${TMP_FILE}
if [ ${?} -eq 0 ]
then
# Update the DeckLink firmware
/usr/bin/xterm -geometry 100x10 -title "DeckLink Firmware Update" -e \
"${UPDATER_BIN} update ${CARD_NUM}; echo ${?} > ${TMP_FILE}; echo This window will be closed in 5 seconds... && sleep 5"
RET_VAL=`cat ${TMP_FILE}`
if [ ${RET_VAL} -eq 0 ]
then
echo "The DeckLink firmware was successfully updated." > ${TMP_FILE}
echo "The system needs to be rebooted before it can be used." >> ${TMP_FILE}
${XMSG_BIN} -center -buttons "Reboot now":0,"Reboot later":1 -default "Reboot now" -file ${TMP_FILE} \
&& DO_REBOOT=1
else
${XMSG_BIN} -center -buttons "Ok":0 "The DeckLink firmware update failed (Return code: ${RET_VAL})."
fi
fi
\rm -f ${TMP_FILE}
if [ ${DO_REBOOT} -eq 1 ]
then
/usr/bin/reboot
fi
fi
exit 0