From 1b9de1cb6c67ec3e75a83896e57e9b3b59883a0e Mon Sep 17 00:00:00 2001 From: Max Krummenacher Date: Wed, 15 Jul 2015 11:45:11 +0200 Subject: update.sh create_configblock.sh: improve test for awk and exit on failure On recent Ubuntu distributions gawk no longer supports awk -V which makes the test fail. Simulate our awk use case and test the result instead. Additionally set 'set -e' to exit immediately on errors. Fix places where a command returns not zero in 'normal' situations. E.g. A full disk leads otherwise to funny effects. Allow relative OUT_DIR. --- recipes/images/files/library/create_configblock.sh | 7 +++++++ recipes/images/files/library/imx6/update.sh | 10 ++++++++-- recipes/images/files/library/tegra/update.sh | 17 ++++++++++++----- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/recipes/images/files/library/create_configblock.sh b/recipes/images/files/library/create_configblock.sh index f21b05c..3829fbb 100755 --- a/recipes/images/files/library/create_configblock.sh +++ b/recipes/images/files/library/create_configblock.sh @@ -1,5 +1,8 @@ #! /bin/sh +# exit on error +set -e + Usage() { echo "create_configblock creates a configblock binary from the info on the module sticker." @@ -31,6 +34,10 @@ while getopts "h" Option ; do esac done +#sanity check for some programs +AWKTEST=`echo 12345678abcdefgh | awk 'BEGIN{ FIELDWIDTHS = "8 8"} {print $2}'` || true +[ "${AWKTEST}x" = "abcdefghx" ] || { echo >&2 "Program gawk not available. Aborting."; exit 1; } + # autotect MODTYPE from from rootfs directory CNT=`grep -c "T20" rootfs/etc/issue || true` if [ ${CNT} -ge 1 ] ; then diff --git a/recipes/images/files/library/imx6/update.sh b/recipes/images/files/library/imx6/update.sh index 96c1ddb..4dd7592 100755 --- a/recipes/images/files/library/imx6/update.sh +++ b/recipes/images/files/library/imx6/update.sh @@ -3,6 +3,9 @@ # # inspired by meta-fsl-arm/classes/image_types_fsl.bbclass +# exit on error +set -e + # sometimes we need the binary echo, not the shell builtin ECHO=`which echo` #some distros have fs tools only in root's path @@ -135,6 +138,10 @@ if [ ! -d "$OUT_DIR" ] ; then exit 1 fi +#sanity check for awk programs +AWKTEST=`echo 100000000 | awk -v min=100 -v f=10000 '{rootfs_size=$1+f*512;rootfs_size=int(rootfs_size/1024/985); print (rootfs_size+min) }'` || true +[ "${AWKTEST}x" = "204x" ] || { echo >&2 "Program awk not available. Aborting."; exit 1; } + #sanity check for correct untared rootfs DEV_OWNER=`ls -ld rootfs/dev | awk '{print $3}'` if [ "${DEV_OWNER}x" != "rootx" ] @@ -157,14 +164,13 @@ sudo ${PARTED} -v >/dev/null 2>&1 || { echo >&2 "Program parted not available. [ "${MKFSVFAT}x" != "x" ] || { echo >&2 "Program mkfs.vfat not available. Aborting."; exit 1; } MKFSEXT3=`sudo which mkfs.ext3` [ "${MKFSEXT3}x" != "x" ] || { echo >&2 "Program mkfs.ext3 not available. Aborting."; exit 1; } -awk -V >/dev/null 2>&1 || { echo >&2 "Program awk not available. Aborting."; exit 1; } dd --help >/dev/null 2>&1 || { echo >&2 "Program dd not available. Aborting."; exit 1; } #make the directory with the outputfiles writable sudo chown $USER: ${BINARIES} #make a file with the used versions for U-Boot, kernel and rootfs -rm ${BINARIES}/versions.txt +rm -f ${BINARIES}/versions.txt touch ${BINARIES}/versions.txt echo "Component Versions" > ${BINARIES}/versions.txt basename "`readlink -e ${BINARIES}/${U_BOOT_BINARY}`" >> ${BINARIES}/versions.txt diff --git a/recipes/images/files/library/tegra/update.sh b/recipes/images/files/library/tegra/update.sh index 8b7ed94..862ceb5 100755 --- a/recipes/images/files/library/tegra/update.sh +++ b/recipes/images/files/library/tegra/update.sh @@ -2,6 +2,9 @@ # Prepare files needed for flashing an Apalis/Colibri T20/T30 module and # copy them to a convenient location for using from a running U-Boot +# exit on error +set -e + # sometimes we need the binary echo, not the shell builtin ECHO=`which echo` #some distros have fs tools only in root's path @@ -223,6 +226,10 @@ if [ ! -d "$OUT_DIR" ] ; then exit 1 fi +#sanity check for awk programs +AWKTEST=`echo 100000000 | awk -v min=100 -v f=10000 '{rootfs_size=$1+f*512;rootfs_size=int(rootfs_size/1024/985); print (rootfs_size+min) }'` || true +[ "${AWKTEST}x" = "204x" ] || { echo >&2 "Program awk not available. Aborting."; exit 1; } + #sanity check for correct untared rootfs DEV_OWNER=`ls -ld rootfs/dev | awk '{print $3}'` if [ "${DEV_OWNER}x" != "rootx" ] @@ -244,10 +251,9 @@ sudo ${PARTED} -v >/dev/null 2>&1 || { echo >&2 "Program parted not available. [ "${MKFSVFAT}x" != "x" ] || { echo >&2 "Program mkfs.vfat not available. Aborting."; exit 1; } MKFSEXT3=`sudo which mkfs.ext3` [ "${MKFSEXT3}x" != "x" ] || { echo >&2 "Program mkfs.ext3 not available. Aborting."; exit 1; } -awk -V >/dev/null 2>&1 || { echo >&2 "Program awk not available. Aborting."; exit 1; } dd --help >/dev/null 2>&1 || { echo >&2 "Program dd not available. Aborting."; exit 1; } -tegra-uboot-flasher/cbootimage -h >/dev/null 2>&1 -[ "$?" -lt 2 ] || { echo >&2 "Program cbootimage not available. 32bit compatibility libs? Aborting."; exit 1; } +CBOOT_CNT=`tegra-uboot-flasher/cbootimage -h | grep -c outputimage` +[ "$CBOOT_CNT" -gt 0 ] || { echo >&2 "Program cbootimage not available. 32bit compatibility libs? Aborting."; exit 1; } if [ "${MODTYPE}" = "colibri-t20" ] ; then #sanity check, can we execute mkfs.ubifs, e.g. see the help text? @@ -266,8 +272,8 @@ fi sudo chown $USER: ${BINARIES} #make a file with the used versions for U-Boot, kernel and rootfs -sudo touch ${BINARIES}/versions.txt -sudo chmod ugo+w ${BINARIES}/versions.txt +rm -f ${BINARIES}/versions.txt +touch ${BINARIES}/versions.txt echo "Component Versions" > ${BINARIES}/versions.txt basename "`readlink -e ${BINARIES}/${U_BOOT_BINARY}`" >> ${BINARIES}/versions.txt if [ "${MODTYPE}" = "colibri-t20" ] ; then @@ -386,6 +392,7 @@ else fi #copy to $OUT_DIR +OUT_DIR=`readlink -f $OUT_DIR` cd ${BINARIES} sudo cp ${CBOOT_IMAGE} ${KERNEL_IMAGETYPE} ${EMMC_PARTS} ${IMAGEFILE}* flash*.img versions.txt "$OUT_DIR" cd .. -- cgit v1.2.3