#!/bin/sh
# backup .icc files on MacOS 10.6 (Snow Leopard) - part of distributive
################################

# $1 - full path to source directory (directory itself not removed)
# $2 - wildcard or file/dir name
function DirectoryRemoveSubset()
{
	echo "DirectoryRemoveSubset [$2] from [$1]"
	find -d "$1" -name "$2" -execdir rm -rfv {} \;	
}

################################
thisScriptPath="$0"
packagePath=$1
targetLocation=$2
targetVolume=$3

echo "thisScriptPath  ${thisScriptPath}."
echo "packagePath  ${packagePath}."
echo "targetLocation  ${targetLocation}."
echo "targetVolume  ${targetVolume}."

applicationTitle=`defaults read "${packagePath}/Contents/Info" AppTitle -string`
applicationTitleFirstLetterLoverCase=`echo ${applicationTitle:0:1} | tr "[A-Z]" "[a-z]"`
applicationTitleCamelCase=`echo $applicationTitle | sed -e "s/ //g" -e "s/^./$applicationTitleFirstLetterLoverCase/g"`

################################
echo "Storing ICC files..."

sourceFolder2="/Library/Image Capture/Devices/${applicationTitle}.app/Contents/Resources"
destinationFolder2="/tmp/__ICDM_PM_ICC_${applicationTitleCamelCase}__"


DirectoryRemoveSubset "/tmp" "__ICDM_PM_ICC_${applicationTitleCamelCase}__"

echo "    Create backup directory $destinationFolder2:"
mkdir -pv "$destinationFolder2"

echo "backup ICC from $sourceFolder2 to $destinationFolder..."
#find "/Library/Image Capture/Devices/Samsung Scanner.app/Contents/Resources" -name '*.icc' -type f -exec sh -c 'exec cp -f "$@" "/tmp/__ICDM_PM_ICC__"' inline {} +
cd "$sourceFolder2"
ls *.icc | cpio -o | (cd "${destinationFolder2}"; cpio -i -m)

echo "OK."
