From d91cdd32c095772e1affa82f0769f9adeed3dd82 Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Thu, 6 May 2021 23:12:03 -0400 Subject: [PATCH] Provide better error messages from createDiskImage. Check for valid ProDOS filenames. General cleanup of the script. --- .DS_Store | Bin 6148 -> 6148 bytes make/createDiskImage | 265 ++++++++++++++++++++++--------------------- 2 files changed, 133 insertions(+), 132 deletions(-) diff --git a/.DS_Store b/.DS_Store index dd42e4a0d1e13800643274dac661d93106e37231..d239e9a87ac2515ea685731e3bf382a776ccea43 100644 GIT binary patch delta 128 zcmZoMXffE}%_4C!sURn_xWvHVIwKP^3o9Et2L~4i7cbZ3RF*Kw=-`a}^5D#r)TG2B z4h~KZ&UgWd>S`l%lgSTRgbg@3#8nM#Jri;(tEy{i>t-^50V5-XX5fd?FlyFj4c7Zi N6B~p#vvd6A2LRLo96A61 delta 74 zcmZoMXffE}&BAzRas+EXw?uWdk-4dkf}xrDTgk}(g(lBcEW>MDr LOq&2 umount "$MOUNTDIR" 2> /dev/null rm -f "$TMPDISKIMAGE" 2> /dev/null rm -f "$TMPBOOTIMAGE" 2> /dev/null @@ -53,84 +55,13 @@ cleanupAndExit() exit 1 } -if [ ! -f "$TEMPLATEDISKIMAGE" ] -then - echo Unable to find the template disk image, $TEMPLATEDISKIMAGE - cleanupAndExit -fi - -if [ ! -f "$TEMPLATEBOOTIMAGE" ] -then - echo Unable to find the template boot image, $TEMPLATEBOOTIMAGE - cleanupAndExit -fi - -mkdir "$TMPDIR" -if [ $? != 0 ] -then - echo Unable to create the mount directory. - cleanupAndExit -fi - -mkdir "$MOUNTDIR" -if [ $? != 0 ] -then - echo Unable to create the mount directory. - cleanupAndExit -fi - -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 +unmount() +{ RETRIES=0 while [ $RETRIES -lt 5 ] do - umount "$MOUNTDIR" + umount "$1" if [ $? -eq 0 ] then break @@ -142,102 +73,172 @@ then if [ $RETRIES -ge 5 ] then - echo Unable to unmount the boot image. - cleanupAndExit + printErrorAndExit "Unable to unmount the disk image." fi +} + + +validateProDOSName() +{ + NAME=`basename $1` + echo $NAME | egrep '^[a-zA-Z][a-zA-Z0-9.]{0,14}$' > /dev/null +} + + +mkdirProDOS() +{ + validateProDOSName "$1" + if [ $? -ne 0 ] + then + printErrorAndExit "Invalid ProDOS name of directory `basename $1`. ProDOS names must be 1 to 15 characters, start with a letter and only letters, numbers and a period can be used in the name." + fi + + mkdir -p "$1" + if [ $? -ne 0 ] + then + printErrorAndExit "Unable to create directory $1" + fi +} + + +cpProDOS() +{ + validateProDOSName "$2" + if [ $? -ne 0 ] + then + printErrorAndExit "Invalid ProDOS name of file `basename $2`. ProDOS names must be 1 to 15 characters, start with a letter and only letters, numbers and a period can be used in the name." + fi + + cp $CPARGS "$1" "$2" + if [ $? -ne 0 ] + then + printErrorAndExit "Unable to create directory $1" + fi +} + + +copyDirs() +{ + OLDDIR=`pwd` + for COPYDIR in $* + do + cd "$COPYDIR" + if [ $? != 0 ] + then + printErrorAndExit "Unable to find $COPYDIR" + fi + + find . -print | while read FILEORDIR + do + if [ -d "$FILEORDIR" ] + then + mkdirProDOS "${MOUNTDIR}/$FILEORDIR" + elif [ -f "$FILEORDIR" ] + then + cpProDOS "$FILEORDIR" "${MOUNTDIR}/$FILEORDIR" + fi + done + cd "$OLDDIR" + done +} + + +if [ ! -f "$TEMPLATEDISKIMAGE" ] +then + printErrorAndExit "Unable to find the template disk image, $TEMPLATEDISKIMAGE" +fi + +if [ ! -f "$TEMPLATEBOOTIMAGE" ] +then + printErrorAndExit "Unable to find the template boot image, $TEMPLATEBOOTIMAGE" +fi + +mkdir "$TMPDIR" +if [ $? != 0 ] +then + printErrorAndExit "Unable to create the mount directory." +fi + +mkdir "$MOUNTDIR" +if [ $? != 0 ] +then + printErrorAndExit "Unable to create the mount directory." +fi + +cp "$TEMPLATEBOOTIMAGE" "$TMPBOOTIMAGE" +if [ $? != 0 ] +then + printErrorAndExit "Unable to copy template boot image." +fi +if [ ! -z "$COPYBOOTDIRS" ] || [ ! -z "BOOTCOPYPATH" ] +then + profuse -orw "$TMPBOOTIMAGE" "$MOUNTDIR" + if [ $? != 0 ] + then + printErrorAndExit "Unable to mount the boot image." + fi + + if [ ! -z "$BOOTCOPYPATH" ] + then + cpProDOS "$FILE" "$MOUNTDIR/$BOOTCOPYPATH" + if [ $? != 0 ] + then + printErrorAndExit "Unable to copy the file to the boot image." + fi + fi + + copyDirs $COPYBOOTDIRS + + unmount "$MOUNTDIR" fi cp "$TEMPLATEDISKIMAGE" "$TMPDISKIMAGE" if [ $? != 0 ] then - echo Unable to copy template disk image. - cleanupAndExit + printErrorAndExit "Unable to copy template disk image." fi profuse -orw "$TMPDISKIMAGE" "$MOUNTDIR" if [ $? != 0 ] then - echo Unable to mount the disk image. - cleanupAndExit + printErrorAndExit "Unable to mount the disk image." fi -cp $CPARGS "$FILE" "$MOUNTDIR" +cpProDOS "$FILE" "$MOUNTDIR" if [ $? != 0 ] then - echo Unable to copy the file to the disk image. - cleanupAndExit + printErrorAndExit "Unable to copy the file to the disk image." fi +copyDirs $COPYDIRS + 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 - cd "$TMPDIR" $ORCA "$OLDDIR/make/tar" cf "$TMPARCHIVE" "$PROGRAM" if [ $? != 0 ] then - echo Unable to create archive. - cleanupAndExit + printErrorAndExit "Unable to create archive." fi cd "$OLDDIR" -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 +unmount "$MOUNTDIR" cp "$TMPDISKIMAGE" "$DISKIMAGE" if [ $? != 0 ] then - echo Unable to copy the disk image to the destination. - cleanupAndExit + printErrorAndExit "Unable to copy the disk image to the destination." fi cp "$TMPBOOTIMAGE" "$DESTBOOTIMAGE" if [ $? != 0 ] then - echo Unable to copy the boot image to the destination. - cleanupAndExit + printErrorAndExit "Unable to copy the boot image to the destination." fi cp "$TMPARCHIVE" "$ARCHIVE" if [ $? != 0 ] then - echo Unable to copy the archive to the destination. - cleanupAndExit + printErrorAndExit "Unable to copy the archive to the destination." fi rm -f "$TMPDISKIMAGE"