#!/bin/bash

#-------------------------------------------------------------------------------
# hscAddToPackage.sh
#
# This shell script is invoked to add a file to a package file.
#
# Usage: hscAddToPackage <fullyQualifiedPackageFileName> <fullyQualifiedFileToAdd> <addAsRelativeFileName>
#
# Return Codes:
# 0 - Add was successful
# Value other than 0 - Add was not successful
#-------------------------------------------------------------------------------

if [ x${2} == x/${3} ];
then 
   # Since files are added as relative and the third parm equals the second parm minus the leading slash,
   # just use the second parm.
   zip ${1} ${2}
else
   # We need to use a different file name in the zip file than the file to add.
   mkdir -p $(dirname /tmp/${3})
   cp --parents --force ${2} /tmp
   mv --force /tmp${2} /tmp/${3}
   cd /tmp
   zip ${1} ${3}
   cd $OLDPWD
   rm -f /tmp/${3}
fi
