#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/sbin/mkcd/mkrr_fs_gnu.sh 1.10 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1999,2006 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)89        1.10  src/bos/usr/sbin/mkcd/mkrr_fs_gnu.sh, cmdbsys, bos720 11/1/06 12:37:41
############################################################
##
## File:  mkrr_fs_gnu
##
## This is sample shell code for creating ISO9660 CD 
## images, with Rock Ridge extensions, using the GNU 
## software application, mkisofs.
##
## If using this script with mkcd, this file must be linked 
## to /usr/sbin/mkrr_fs.  For example:
##    ln -s /usr/samples/oem_cdwriters/mkrr_fs_gnu /usr/sbin/mkrr_fs
##
## Parameters:  output_file file_system
##                use_dvd_flag (any non-zero parameter)
##                output_file (i.e. /mkcd/cd_images/cd_image_67890)
##                file_system (i.e. /mkcd/cd_fs/67890)
##
## Return Codes:  0 for successful
##                1 for unsuccessful
##
##
############################################################

export PATH="/usr/bin:/usr/sbin:/etc:$PATH"
MSGBUF=/tmp/.mkrr_fs.tmp.msg
## Two possible locations for mkisofs
[[ -s /usr/bin/mkisofs ]] && MKISOFS_PATH=/usr/bin || MKISOFS_PATH=/usr/local/bin

if [ $# -eq 3 ]; then
   DVD_FLAG=$1    ## Dummy variable to remain standard with mkcd
   OUTPUT_FILE=$2
   FS_NODE=$3
elif [ $# -eq 2 ]; then
   OUTPUT_FILE=$1
   FS_NODE=$2
else
   echo "mkrr_fs: Syntax error."
   echo "Usage: mkrr_fs output_file fs_node"
   return 1
fi

############################################################
##  **NOTE: mkisofs v1.12 must be installed to use the "-U"
##          flag.  This will create untranslated directory
##          and file names (non-ISO9660), but will allow
##          proper booting on CHRP systems.
############################################################

UFLAG=
CMDVER=`$MKISOFS_PATH/mkisofs -version | awk '{print$2}'`
VER=`echo $CMDVER | awk -F. '{print$1}'`
REL=`echo $CMDVER | awk -F. '{print$2}'`

[[ $VER -eq 1 ]] && [[ $REL = "12" ]] && UFLAG="-U"
[[ $VER -eq 1 ]] && [[ $REL > "12" ]] && UFLAG="-U"
[[ $VER -ge 2 ]] && UFLAG="-U"

echo "Running mkisofs ..."
if [[ $REL = "12" || $REL > "12" ]]; then
   $MKISOFS_PATH/mkisofs $UFLAG -r -o $OUTPUT_FILE $FS_NODE 2>$MSGBUF
else
   $MKISOFS_PATH/mkisofs $UFLAG -a -r -o $OUTPUT_FILE $FS_NODE 2>$MSGBUF
fi
if [ $? -ne 0 ]; then
   echo ""
   cat $MSGBUF 
   echo "Error mkrr_fs: command error."
   rm -f $MSGBUF
   return 1
else
   echo ""
   echo "mkrr_fs was successful."
   rm -f $MSGBUF
   return 0
fi
