#! /bin/zsh
setopt EXTENDED_GLOB
setopt NULL_GLOB
setopt GLOB_DOTS
SetFilePath=${NEXT_ROOT}/System/Developer/Tools/SetFile
PlistConverterPath=${NEXT_ROOT}/usr/bin/CFInfoPlistConverter
if [ "$#" -lt "1" ] ; then
echo "Usage: $0 <bundlePath>"
exit 1
fi
bundlePath="$1"
bundleDir="${bundlePath:h}"
bundleName="${bundlePath:t:r}"
bundleType="${bundlePath:e}"
if [ "${bundleDir}" = "${bundlePath}" ] ; then
bundleDir=`pwd`
fi
if [ \! -e "${bundleDir}/${bundleName}.${bundleType}" ] ; then
echo "${bundleDir}/${bundleName}.${bundleType} does not seem to exist. Exiting"
exit 1
fi
echo "Converting bundle named ${bundleName} of type ${bundleType} \n in directory ${bundleDir}."
cd ${bundleDir}/${bundleName}.${bundleType}
mkdir "Contents"
if [ \! -e "${bundleDir}/${bundleName}.${bundleType}/Contents" ] ; then
echo "Could not create Contents folder. Exiting"
exit 1
fi
cd ${bundleDir}/${bundleName}.${bundleType}
if [ -d "Resources" ] ; then
echo -n "Doing Info.plist..."
for i in `ls Resources/Info*.plist` ; do
mv ${i} "Contents"
done
cd "Contents"
if [ ! -e "Info-macos.plist" ] ; then
if [ -e "Info-macosx.plist" ] ; then
mv "Info-macosx.plist" "Info-macos.plist"
elif [ -e "Info-macintosh.plist" ] ; then
mv "Info-macintosh.plist" "Info-macos.plist"
elif [ -e "Info-nextstep.plist" ] ; then
mv "Info-nextstep.plist" "Info-macos.plist"
fi
fi
rm -f "Info-macosx.plist" "Info-macintosh.plist" "Info-nextstep.plist"
if [ ! -e "Info-windows.plist" ] ; then
if [ -e "Info-winnt.plist" ] ; then
mv "Info-winnt.plist" "Info-windows.plist"
elif [ -e "Info-win32.plist" ] ; then
mv "Info-win32.plist" "Info-windows.plist"
fi
fi
rm -f "Info-winnt.plist" "Info-win32.plist"
if [ ! -e "Info-macosclassic.plist" ] ; then
if [ -e "Info-macos8.plist" ] ; then
mv "Info-macos8.plist" "Info-macosclassic.plist"
fi
fi
rm -f "Info-macos8.plist"
if [ "${PlistConverterPath}" -a -x "${PlistConverterPath}" ] ; then
for i in `ls Info*.plist` ; do
${PlistConverterPath} "${bundleDir}/${bundleName}.${bundleType}" "`pwd`/${i}" "${bundleType}"
done
fi
echo "done."
fi
cd ${bundleDir}/${bundleName}.${bundleType}
if [ -d "Resources" ] ; then
echo -n "Doing Resources..."
mv "Resources" "Contents"
cd "Contents/Resources"
for curLProj in `ls -d *.lproj` "." ; do
echo converting files in Resources/$curLProj
cd "${bundleDir}/${bundleName}.${bundleType}/Contents/Resources/${curLProj}"
files=`ls -d *-macosx.*`
for curResource in ${(f)files} ; do
if [ "${curResource}" != "." ] ; then
mv ${curResource} ${curResource:s/-macosx/-macos/}
fi
done
files=`ls -d *-macosx`
for curResource in ${(f)files} ; do
if [ "${curResource}" != "." ] ; then
mv ${curResource} ${curResource:s/-macosx/-macos/}
fi
done
files=`ls -d *-winnt.*`
for curResource in ${(f)files} ; do
if [ "${curResource}" != "." ] ; then
mv ${curResource} ${curResource:s/-winnt/-windows/}
fi
done
files=`ls -d *-winnt`
for curResource in ${(f)files} ; do
if [ "${curResource}" != "." ] ; then
mv ${curResource} ${curResource:s/-winnt/-windows/}
fi
done
files=`ls -d *-win32.*`
for curResource in ${(f)files} ; do
if [ "${curResource}" != "." ] ; then
mv ${curResource} ${curResource:s/-win32/-windows/}
fi
done
files=`ls -d *-win32`
for curResource in ${(f)files} ; do
if [ "${curResource}" != "." ] ; then
mv ${curResource} ${curResource:s/-win32/-windows/}
fi
done
files=`ls -d *-macos8.*`
for curResource in ${(f)files} ; do
if [ "${curResource}" != "." ] ; then
mv ${curResource} ${curResource:s/-macos8/-macosclassic/}
fi
done
files=`ls -d *-macos8`
for curResource in ${(f)files} ; do
if [ "${curResource}" != "." ] ; then
mv ${curResource} ${curResource:s/-macos8/-macosclassic/}
fi
done
done
echo "done."
fi
cd ${bundleDir}/${bundleName}.${bundleType}
if [ -x "${bundleName}" ] ; then
echo -n "Doing Executables..."
mkdir -p "Contents/MacOS"
mv "${bundleName}" "Contents/MacOS"
if [ -d "${bundleName}..." ]; then
mv "${bundleName}..." "Contents/MacOS"
fi
if [ -e ".%${bundleName}" ]; then
mv ".%${bundleName}" "Contents/MacOS"
fi
if [ -e "._${bundleName}" ]; then
mv "._${bundleName}" "Contents/MacOS"
fi
echo "done."
fi