diff options
author | Sven Eckelmann <sven.eckelmann@open-mesh.com> | 2017-11-30 14:30:06 +0100 |
---|---|---|
committer | Mathias Kresin <dev@kresin.me> | 2018-01-13 07:58:46 +0100 |
commit | 1a384ac0b553433dd5049068e70425c421b796f8 (patch) | |
tree | a6daed598c0545b3ad64117ad6b766c2727233de /scripts | |
parent | 9514cde2b95307f51f60183f31d76925a49ee55d (diff) | |
download | upstream-1a384ac0b553433dd5049068e70425c421b796f8.tar.gz upstream-1a384ac0b553433dd5049068e70425c421b796f8.tar.bz2 upstream-1a384ac0b553433dd5049068e70425c421b796f8.zip |
combined-ext-image.sh: generate image in temp dir
The new build commands operate on the input image and use it again as
output image. This conflicts with the way combined-ext-image.sh was
operating. It required that input and output files are different files and
and that it can write freely to the output file.
This can be avoided when all intermediate build steps by
combined-ext-image.sh are done in a temporary directory. The output file is
then only overwritten in the last step.
Signed-off-by: Sven Eckelmann <sven.eckelmann@open-mesh.com>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/combined-ext-image.sh | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/scripts/combined-ext-image.sh b/scripts/combined-ext-image.sh index 0c7b1d993d..7ff287bde7 100755 --- a/scripts/combined-ext-image.sh +++ b/scripts/combined-ext-image.sh @@ -22,6 +22,8 @@ ## version history # * version 1: initial file format with num files / name / length / md5 checksum +set -e + ME="${0##*/}" usage() { @@ -38,7 +40,21 @@ IMG_OUT=$1; shift FILE_NUM=$(($# / 2)) FILES="" -printf "CE%02x%-32s%02x" $CE_VERSION "$IMG_TYPE" $FILE_NUM > $IMG_OUT +tmpdir="$( mktemp -d 2> /dev/null )" +if [ -z "$tmpdir" ]; then + # try OSX signature + tmpdir="$( mktemp -t 'ubitmp' -d )" +fi + +if [ -z "$tmpdir" ]; then + exit 1 +fi + +trap "rm -rf $tmpdir" EXIT + +IMG_TMP_OUT="${tmpdir}/out" + +printf "CE%02x%-32s%02x" $CE_VERSION "$IMG_TYPE" $FILE_NUM > "${IMG_TMP_OUT}" while [ "$#" -gt 1 ] do @@ -48,14 +64,15 @@ while [ "$#" -gt 1 ] [ ! -f "$file" ] && echo "$ME: Not a valid file: $file" && usage FILES="$FILES $file" md5=$(mkhash md5 "$file") - printf "%-32s%08x%32s" "$filename" $(stat -c "%s" "$file") "${md5%% *}" >> $IMG_OUT + printf "%-32s%08x%32s" "$filename" $(stat -c "%s" "$file") "${md5%% *}" >> "${IMG_TMP_OUT}" shift 2 done [ "$#" -eq 1 ] && echo "$ME: Filename not specified: $1" && usage -mv $IMG_OUT $IMG_OUT.tmp -dd if="$IMG_OUT.tmp" of="$IMG_OUT" bs=65536 conv=sync 2>/dev/null -rm $IMG_OUT.tmp +mv "${IMG_TMP_OUT}" "${IMG_TMP_OUT}".tmp +dd if="${IMG_TMP_OUT}.tmp" of="${IMG_TMP_OUT}" bs=65536 conv=sync 2>/dev/null +rm "${IMG_TMP_OUT}".tmp -cat $FILES >> $IMG_OUT +cat $FILES >> "${IMG_TMP_OUT}" +cp "${IMG_TMP_OUT}" "${IMG_OUT}" |