#!/usr/bin/env bash
# Run grub-mkrescue to create an iso.img file
#
# Parameters:
#   $1 is the file to execute
#   $2 grub.cfg file
#   $3 iso image file
tmpdir=$(mktemp -d /tmp/grub-mkrescue.isofiles.XXX)
#echo "'tmpdir=${tmpdir}"
mkdir -p ${tmpdir}/boot/grub
cp $1 ${tmpdir}/boot/
cp $2 ${tmpdir}/boot/grub/grub.cfg
grub-mkrescue -o $3 ${tmpdir} 2> /dev/null
rm -rf ${tmpdir}

#!/usr/bin/env bash
# Run grub-mkrescue to create an iso.img file
#
# Parameters:
#   $1 is the file to execute
#   $2 grub.cfg file
#   $3 iso image file
#set -x
tmpdir=$(mktemp -d /tmp/grub-mkrescue.isofiles.XXX)
#echo "'tmpdir=${tmpdir}"
mkdir -p ${tmpdir}/boot/grub
cp $1 ${tmpdir}/boot/
cp $2 ${tmpdir}/boot/grub/grub.cfg
tmpdir="xxxx"
# Turns out grub-mkresule doesn't report an error if the input file doesn't
# exist. I posted an email to help-grub@gnu.org to find out why, but that
# probably means ther might be other reasons a failure won't be reported
# so this test may not be useful.
grub-mkrescue -d /usr/lib/grub/i386-pc/ -o $3 ${tmpdir} 2> /dev/null || { echo "grub-mkrescue fialed with $?"; exit 1; }
rm -rf ${tmpdir}

Add testing for errors from grub-mkrescue
Add testing for errors from grub-mkrescue

But as I said in the comment it doesn't always report an error, in
particular if xorriso reports a failure:

$ grub-mkrescue -o xx.img xx
xorriso 1.4.2 : RockRidge filesystem manipulator, libburnia project.

Drive current: -outdev 'stdio:xx.img'
Media current: stdio file, overwriteable
Media status : is blank
Media summary: 0 sessions, 0 data blocks, 0 data,  421g free
Added to ISO image: directory '/'='/tmp/grub.vDHSgN'
xorriso : UPDATE : 875 files added in 1 seconds
xorriso : FAILURE : Cannot determine attributes of source file '/home/wink/prgs/sadie/build-pc_x86_64/xx' : No such file or directory
xorriso : UPDATE : 875 files added in 1 seconds
xorriso : aborting : -abort_on 'FAILURE' encountered 'FAILURE'
wink@wink-desktop:~/prgs/sadie/build-pc_x86_64
$ echo $?
0
