mirror of
https://github.com/jeremysrand/Apple2GSBuildPipeline.git
synced 2024-12-01 14:50:19 +00:00
135 lines
2.6 KiB
Bash
Executable File
135 lines
2.6 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
|
|
MOUNTDIR=/tmp/a2gs_mount.$$
|
|
TMPDISKIMAGE=/tmp/a2gs_diskimage_$$.2mg
|
|
TEMPLATEDISKIMAGE=make/system601.2mg
|
|
|
|
if [ $# -lt 3 ]
|
|
then
|
|
echo USAGE: $0 diskimage file directory
|
|
exit 1
|
|
fi
|
|
|
|
DISKIMAGE="$1"
|
|
shift
|
|
|
|
FILE="$1"
|
|
shift
|
|
|
|
DISKIMAGEDEST="$1"
|
|
shift
|
|
DEST="${MOUNTDIR}/${DISKIMAGEDEST}"
|
|
|
|
COPYDIRS=$*
|
|
|
|
# It looks like on Linux, the cp command needs a special argument to preserve the resource fork. This isn't ideal
|
|
# but for now, if uname is Darwin, then this is MacOS and we don't need any cp args. If not Darwin, then assume
|
|
# this is Linux and ask for extended attributes to be preserved through the copy.
|
|
#
|
|
# Ultimately, it could be that other platforms (BSD, does Solaris still exist?) or even other Linux versions or
|
|
# distributions need different arguments for this rather special thing. If true, this may need to be a build time
|
|
# option which can be set.
|
|
if [ "`uname`" = Darwin ]
|
|
then
|
|
CPARGS=""
|
|
else
|
|
CPARGS="--preserve=xattr"
|
|
fi
|
|
|
|
cleanupAndExit()
|
|
{
|
|
umount "$MOUNTDIR" 2> /dev/null
|
|
rm -f "$TMPDISKIMAGE" 2> /dev/null
|
|
rm -f "$DISKIMAGE" 2> /dev/null
|
|
rmdir "$MOUNTDIR" 2> /dev/null
|
|
exit 1
|
|
}
|
|
|
|
if [ ! -f "$TEMPLATEDISKIMAGE" ]
|
|
then
|
|
echo Unable to find the template disk image, $TEMPLATEDISKIMAGE
|
|
cleanupAndExit
|
|
fi
|
|
|
|
cp "$TEMPLATEDISKIMAGE" "$TMPDISKIMAGE"
|
|
if [ $? != 0 ]
|
|
then
|
|
echo Unable to copy template disk image.
|
|
cleanupAndExit
|
|
fi
|
|
|
|
mkdir "$MOUNTDIR"
|
|
if [ $? != 0 ]
|
|
then
|
|
echo Unable to create the mount directory.
|
|
cleanupAndExit
|
|
fi
|
|
|
|
profuse -orw "$TMPDISKIMAGE" "$MOUNTDIR"
|
|
if [ $? != 0 ]
|
|
then
|
|
echo Unable to mount the disk image.
|
|
cleanupAndExit
|
|
fi
|
|
|
|
cp $CPARGS "$FILE" "$DEST"
|
|
if [ $? != 0 ]
|
|
then
|
|
echo Unable to copy the file to the disk image.
|
|
cleanupAndExit
|
|
fi
|
|
|
|
OLDDIR=`pwd`
|
|
for COPYDIR in $COPYDIRS
|
|
do
|
|
cd "$COPYDIR"
|
|
if [ $? != 0 ]
|
|
then
|
|
echo Unable to find $COPYDIR
|
|
cleanupAndExit
|
|
fi
|
|
|
|
find . -print | while read FILEORDIR
|
|
do
|
|
if [ -d "$FILEORDIR" ]
|
|
then
|
|
mkdir -p "${MOUNTDIR}/$FILEORDIR"
|
|
elif [ -f "$FILEORDIR" ]
|
|
then
|
|
cp $CPARGS "$FILEORDIR" "${MOUNTDIR}/$FILEORDIR"
|
|
fi
|
|
done
|
|
cd "$OLDDIR"
|
|
done
|
|
|
|
RETRIES=0
|
|
while [ $RETRIES -lt 5 ]
|
|
do
|
|
umount "$MOUNTDIR"
|
|
if [ $? -eq 0 ]
|
|
then
|
|
break
|
|
fi
|
|
|
|
RETRIES=`expr $RETRIES + 1`
|
|
sleep 1
|
|
done
|
|
|
|
if [ $RETRIES -ge 5 ]
|
|
then
|
|
echo Unable to unmount the disk image.
|
|
cleanupAndExit
|
|
fi
|
|
|
|
cp "$TMPDISKIMAGE" "$DISKIMAGE"
|
|
if [ $? != 0 ]
|
|
then
|
|
echo Unable to copy the disk image to the destination.
|
|
cleanupAndExit
|
|
fi
|
|
|
|
rm -f "$TMPDISKIMAGE"
|
|
rmdir "$MOUNTDIR"
|
|
exit 0
|