#!/usr/bin/bash
#
# copyright c 2001-2007 by isilon systems, inc. all rights not expressly
# granted herein are reserved.
# created in the united states of america.
# 
# this digital media is protected by u.s. and international copyright and
# intellectual property laws. unless otherwise specified, all information
# and screens appearing as part of this digital medium, including
# software, services, documents, text, images, icons, and logos design;
# the selection, assembly, arrangement, and design thereof; and the code
# that enables its presentation, are the sole property of isilon systems,
# inc.
# 
# except as otherwise required by applicable law, no part of any
# copyrighted material may be reproduced, modified, translated,
# distributed, published, or transmitted by any means, electronic or
# mechanical, for any purpose, without the prior written consent of isilon
# systems. 
#  
# isilon and isilon systems are registered trademarks of isilon systems,
# inc.  legion is a trademark of isilon systems, inc.  all other
# trademarks and registered trademarks are the property of their
# respective holders.
#

# This is a wrapper script that calls isi_inventory_tool 
# to generate a new ABR and enforces the filename format per spec.
# Exporting with a given filename correctly records the filename format
# within the xml file as the attribute "asbuiltfilename"
# 
# Once the export is successful, it deletes that file. The only part 
# of the export process we're interested in that the filename registering
# correctly. 
#
# The audience for this script is for Global Services and Field usage.

serial=`sed -e 's/-//g' /etc/isilon_serial_number`
datetime=`date '+%Y%m%d%H%M'`
filepath="/tmp/asbuilt_${serial}_${datetime}.xml"

echo "Running isi_inventory_tool to export temporary ABR."

/usr/bin/isi_inventory_tool --exportFile --fileType=asbuilt --filePath=${filepath}

if [ $? -eq 1 ]; then
    #Error in ABR export
    echo "Failed to export ABR."
    rm -f ${filepath}
    exit 1
else
    #ABR export success. #Remove abr.
    echo "ABR export successful. Removing temporary ABR."
    rm -f ${filepath}
    exit 0
fi

