2017-07-17 00:56:17 -04:00
|
|
|
#!/bin/sh
|
|
|
|
|
2017-08-30 23:35:49 -04:00
|
|
|
if [ $# -lt 3 ]
|
2017-07-17 00:56:17 -04:00
|
|
|
then
|
2021-04-13 00:04:59 -04:00
|
|
|
echo USAGE: $0 diskimage bootimage file [bootdest]
|
2017-07-17 00:56:17 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
DISKIMAGE="$1"
|
2017-08-30 23:35:49 -04:00
|
|
|
shift
|
|
|
|
|
2021-04-13 00:04:59 -04:00
|
|
|
DESTBOOTIMAGE="$1"
|
2017-08-30 23:35:49 -04:00
|
|
|
shift
|
|
|
|
|
2021-04-13 00:04:59 -04:00
|
|
|
FILE="$1"
|
2017-08-30 23:35:49 -04:00
|
|
|
shift
|
|
|
|
|
2021-04-13 00:04:59 -04:00
|
|
|
BOOTCOPYPATH="$1"
|
|
|
|
|
|
|
|
PROGRAM=`basename "$FILE"`
|
|
|
|
TMPDIR=/tmp/a2gs_mount.$$
|
|
|
|
MOUNTDIR="${TMPDIR}/$PROGRAM"
|
|
|
|
TMPDISKIMAGE=/tmp/a2gs_diskimage_$$.2mg
|
|
|
|
TMPBOOTIMAGE=/tmp/a2gs_bootimage_$$.2mg
|
|
|
|
TMPARCHIVE=/tmp/s2gs_archive_$$.shk
|
|
|
|
TEMPLATEDISKIMAGE="make/empty.2mg"
|
|
|
|
TEMPLATEBOOTIMAGE="make/$BOOTIMAGE"
|
|
|
|
ARCHIVE=`dirname "$DISKIMAGE"`/"${PROGRAM}.shk"
|
2017-07-17 00:56:17 -04:00
|
|
|
|
2020-11-30 00:31:21 -05:00
|
|
|
# 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
|
|
|
|
|
2017-07-17 00:56:17 -04:00
|
|
|
cleanupAndExit()
|
|
|
|
{
|
|
|
|
umount "$MOUNTDIR" 2> /dev/null
|
|
|
|
rm -f "$TMPDISKIMAGE" 2> /dev/null
|
2021-04-13 00:04:59 -04:00
|
|
|
rm -f "$TMPBOOTIMAGE" 2> /dev/null
|
|
|
|
rm -f "$TMPARCHIVE" 2> /dev/null
|
2017-07-17 00:56:17 -04:00
|
|
|
rm -f "$DISKIMAGE" 2> /dev/null
|
2021-04-13 00:04:59 -04:00
|
|
|
rm -f "$DESTBOOTIMAGE" 2> /dev/null
|
|
|
|
rm -rf "$TMPDIR" 2> /dev/null
|
2017-07-17 00:56:17 -04:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ ! -f "$TEMPLATEDISKIMAGE" ]
|
|
|
|
then
|
|
|
|
echo Unable to find the template disk image, $TEMPLATEDISKIMAGE
|
|
|
|
cleanupAndExit
|
|
|
|
fi
|
|
|
|
|
2021-04-13 00:04:59 -04:00
|
|
|
if [ ! -f "$TEMPLATEBOOTIMAGE" ]
|
|
|
|
then
|
|
|
|
echo Unable to find the template boot image, $TEMPLATEBOOTIMAGE
|
|
|
|
cleanupAndExit
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir "$TMPDIR"
|
2017-07-17 00:56:17 -04:00
|
|
|
if [ $? != 0 ]
|
|
|
|
then
|
2021-04-13 00:04:59 -04:00
|
|
|
echo Unable to create the mount directory.
|
2017-07-17 00:56:17 -04:00
|
|
|
cleanupAndExit
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir "$MOUNTDIR"
|
|
|
|
if [ $? != 0 ]
|
|
|
|
then
|
|
|
|
echo Unable to create the mount directory.
|
|
|
|
cleanupAndExit
|
|
|
|
fi
|
|
|
|
|
2021-04-13 00:04:59 -04:00
|
|
|
cp "$TEMPLATEBOOTIMAGE" "$TMPBOOTIMAGE"
|
|
|
|
if [ $? != 0 ]
|
|
|
|
then
|
|
|
|
echo Unable to copy template boot image.
|
|
|
|
cleanupAndExit
|
|
|
|
fi
|
|
|
|
if [ ! -z "$COPYBOOTDIRS" ] || [ ! -z "BOOTCOPYPATH" ]
|
|
|
|
then
|
|
|
|
profuse -orw "$TMPBOOTIMAGE" "$MOUNTDIR"
|
|
|
|
if [ $? != 0 ]
|
|
|
|
then
|
|
|
|
echo Unable to mount the boot image.
|
|
|
|
cleanupAndExit
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -z "$BOOTCOPYPATH" ]
|
|
|
|
then
|
|
|
|
cp $CPARGS "$FILE" "$MOUNTDIR/$BOOTCOPYPATH"
|
|
|
|
if [ $? != 0 ]
|
|
|
|
then
|
|
|
|
echo Unable to copy the file to the boot image.
|
|
|
|
cleanupAndExit
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
OLDDIR=`pwd`
|
|
|
|
for COPYDIR in $COPYBOOTDIRS
|
|
|
|
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 boot image.
|
|
|
|
cleanupAndExit
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
cp "$TEMPLATEDISKIMAGE" "$TMPDISKIMAGE"
|
|
|
|
if [ $? != 0 ]
|
|
|
|
then
|
|
|
|
echo Unable to copy template disk image.
|
|
|
|
cleanupAndExit
|
|
|
|
fi
|
|
|
|
|
2017-07-17 00:56:17 -04:00
|
|
|
profuse -orw "$TMPDISKIMAGE" "$MOUNTDIR"
|
|
|
|
if [ $? != 0 ]
|
|
|
|
then
|
|
|
|
echo Unable to mount the disk image.
|
|
|
|
cleanupAndExit
|
|
|
|
fi
|
|
|
|
|
2021-04-13 00:04:59 -04:00
|
|
|
cp $CPARGS "$FILE" "$MOUNTDIR"
|
2017-07-17 00:56:17 -04:00
|
|
|
if [ $? != 0 ]
|
|
|
|
then
|
|
|
|
echo Unable to copy the file to the disk image.
|
|
|
|
cleanupAndExit
|
|
|
|
fi
|
|
|
|
|
2017-08-30 23:35:49 -04:00
|
|
|
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
|
2020-11-30 00:31:21 -05:00
|
|
|
cp $CPARGS "$FILEORDIR" "${MOUNTDIR}/$FILEORDIR"
|
2017-08-30 23:35:49 -04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
cd "$OLDDIR"
|
|
|
|
done
|
|
|
|
|
2021-04-13 00:04:59 -04:00
|
|
|
cd "$TMPDIR"
|
|
|
|
$ORCA "$OLDDIR/make/tar" cf "$TMPARCHIVE" "$PROGRAM"
|
|
|
|
if [ $? != 0 ]
|
|
|
|
then
|
|
|
|
echo Unable to create archive.
|
|
|
|
cleanupAndExit
|
|
|
|
fi
|
|
|
|
cd "$OLDDIR"
|
|
|
|
|
2018-07-27 23:29:49 -04:00
|
|
|
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 ]
|
2017-07-17 00:56:17 -04:00
|
|
|
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
|
|
|
|
|
2021-04-13 00:04:59 -04:00
|
|
|
cp "$TMPBOOTIMAGE" "$DESTBOOTIMAGE"
|
|
|
|
if [ $? != 0 ]
|
|
|
|
then
|
|
|
|
echo Unable to copy the boot image to the destination.
|
|
|
|
cleanupAndExit
|
|
|
|
fi
|
|
|
|
|
|
|
|
cp "$TMPARCHIVE" "$ARCHIVE"
|
|
|
|
if [ $? != 0 ]
|
|
|
|
then
|
|
|
|
echo Unable to copy the archive to the destination.
|
|
|
|
cleanupAndExit
|
|
|
|
fi
|
|
|
|
|
2017-07-17 00:56:17 -04:00
|
|
|
rm -f "$TMPDISKIMAGE"
|
2021-04-13 00:04:59 -04:00
|
|
|
rm -f "$TMPBOOTIMAGE"
|
|
|
|
rm -f "$TMPARCHIVE"
|
|
|
|
rm -rf "$TMPDIR"
|
2017-07-17 00:56:17 -04:00
|
|
|
exit 0
|