I read thru the meat of the script and saw a possible failure point. The part I’m referencing is:
[code]
for UPDATE_PKG in `ls $UPDATE_FOLDER`
do
/usr/sbin/installer -verbose -pkg ${UPDATE_FOLDER}/${UPDATE_PKG} -target $CURRENT_IMAGE_MOUNT >> $LOG_FILE
/bin/echo “Installed $UPDATE_PKG” >> $PKG_LOG
done
[/code]
The problem lies in the file names and using ‘ls’ to read those names. The default IFS is a space and so any .pkg name with a space in it would fail since the for loop thought the file was “Package” instead of “Package 1.pkg”. Apple does have some packages with spaces in the names so its not totally controlable. Below is how I handled this issue.
Basically I have a file specifying the order of the pkg files in a list separated by a custom IFS delimiter. For my script the list would look like “SafariUpdate1.3.1.pkg|SafariUpdate1.3.2.pkg|QuickTime704.pkg” and would install the packages in that order from left to right.
The code below is not complete, just the bits to work around this issue.
=====
[code]
# Specify the delimiter for the “for” loop. Default is space. Using pipe.
IFS=”|”
# name of text file containing order specific packages.
# File should be the exact package names delimited all on one line by a pipe (|)
# or whatever the IFS is set to.
orderFile=”packageOrder.txt”
# check to see if a file containing a specific package order exists. If so read the file to get the order.
if [ -f ${dir}${orderFile} ]
then
packages=`cat ${dir}${orderFile}`
….
fi
after about 15 minutes of playing
– indeedy do! the line
[code] for update_pkg in `ls $update_folder`[/code]
will behave poorly or not at all if there is a space in the file name(s)
so instead of the lengthy code blob suggested – how about replacing the line with this?
[code]ls -1 $UPDATE_FOLDER | while read UPDATE_PKG[/code]
do the same in the custom_pkg section
does that completely solve the issue?
– would there be a case where some other character than a space in a filename might much this?
That’s a slick fix. I wish I knew that sooner. Learn something new every day…
Just make sure the ‘installer’ command using $UPDATE_PKG is in quotes to preserve the spaces in the path.
I didn’t know this would work before so I don’t know if anything will hang it up. Most every .pkg file has pretty standard characters. I’d say assume user’s custom .pkg files won’t include any characters other than Apple’s supplied .pkg files..which have consistently been alpha-numeric.
The issue of specifying the order of installations is still there though.
Comments are closed