summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Agner <stefan.agner@toradex.com>2016-04-19 15:55:56 -0700
committerMarcel Ziswiler <marcel.ziswiler@toradex.com>2016-06-24 00:50:59 +0200
commit82057d57480e53d339c8b6801169ad1509e3cb8b (patch)
tree2dc324178b09cfbc5ba36ec00ddb27e4825327ef
parent08058cb91c28a0b28dc4767e4d1683e3d3cab496 (diff)
update.sh: use command instead of which
Use "command" instead of "which" for sanity checks. This is preferable to several reasons, see: http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script Also always use or (||) syntax to avoid bash script exits. Tested to be working on Ubuntu, Fedora and Arch Linux. Signed-off-by: Stefan Agner <stefan.agner@toradex.com> Acked-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
-rwxr-xr-xrecipes/images/files/library/imx6/update.sh21
-rwxr-xr-xrecipes/images/files/library/tegra/update.sh22
2 files changed, 11 insertions, 32 deletions
diff --git a/recipes/images/files/library/imx6/update.sh b/recipes/images/files/library/imx6/update.sh
index 10043e1..0bf5380 100755
--- a/recipes/images/files/library/imx6/update.sh
+++ b/recipes/images/files/library/imx6/update.sh
@@ -6,15 +6,6 @@
# exit on error
set -e
-#some distros have fs tools only in root's path
-PARTED=`which parted` 2> /dev/null || true
-if [ -e "$PARTED" ] ; then
- MKFSVFAT=`which mkfs.vfat`
-else
- PARTED=`sudo which parted`
- MKFSVFAT=`sudo which mkfs.vfat`
-fi
-
Flash()
{
echo "To flash the Apalis/Colibri iMX6 module a running U-Boot is required. Boot the"
@@ -161,13 +152,11 @@ fi
[ -e ${BINARIES}/${U_BOOT_BINARY_IT} ] || { echo "${BINARIES}/${U_BOOT_BINARY_IT} does not exist"; exit 1; }
[ -e ${BINARIES}/uImage ] || { echo "${BINARIES}/uImage does not exist"; exit 1; }
-#sanity check for some programs
-MCOPY=`sudo which mcopy`
-[ "${MCOPY}x" != "x" ] || { echo >&2 "Program mcopy not available. Aborting."; exit 1; }
-sudo ${PARTED} -v >/dev/null 2>&1 || { echo >&2 "Program parted not available. Aborting."; exit 1; }
-[ "${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; }
+#Sanity check for some programs. Some distros have fs tools only in root's path
+MCOPY=`command -v mcopy` || { echo >&2 "Program mcopy not available. Aborting."; exit 1; }
+PARTED=`command -v parted` || PARTED=`sudo -s command -v parted` || { echo >&2 "Program parted not available. Aborting."; exit 1; }
+MKFSVFAT=`command -v mkfs.vfat` || MKFSVFAT=`sudo -s command -v mkfs.vfat` || { echo >&2 "Program mkfs.vfat not available. Aborting."; exit 1; }
+MKFSEXT3=`command -v mkfs.ext3` || MKFSEXT3=`sudo -s command -v mkfs.ext3` || { echo >&2 "Program mkfs.ext3 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
diff --git a/recipes/images/files/library/tegra/update.sh b/recipes/images/files/library/tegra/update.sh
index 71e25f8..3d3a7db 100755
--- a/recipes/images/files/library/tegra/update.sh
+++ b/recipes/images/files/library/tegra/update.sh
@@ -5,15 +5,6 @@
# exit on error
set -e
-#some distros have fs tools only in root's path
-PARTED=`which parted` 2> /dev/null || true
-if [ -e "$PARTED" ] ; then
- MKFSVFAT=`which mkfs.vfat`
-else
- PARTED=`sudo which parted`
- MKFSVFAT=`sudo which mkfs.vfat`
-fi
-
Flash()
{
echo "To flash the Apalis/Colibri T20/T30 module a running U-Boot is required. Boot"
@@ -241,14 +232,13 @@ fi
[ -e ${BINARIES}/${U_BOOT_BINARY} ] || { echo "${BINARIES}/${U_BOOT_BINARY} does not exist"; exit 1; }
[ -e ${BINARIES}/${KERNEL_IMAGETYPE} ] || { echo "${BINARIES}/${KERNEL_IMAGETYPE} does not exist"; exit 1; }
-#sanity check for some programs
-MCOPY=`sudo which mcopy`
-[ "${MCOPY}x" != "x" ] || { echo >&2 "Program mcopy not available. Aborting."; exit 1; }
-sudo ${PARTED} -v >/dev/null 2>&1 || { echo >&2 "Program parted not available. Aborting."; exit 1; }
-[ "${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; }
+#Sanity check for some programs. Some distros have fs tools only in root's path
+MCOPY=`command -v mcopy` || { echo >&2 "Program mcopy not available. Aborting."; exit 1; }
+PARTED=`command -v parted` || PARTED=`sudo -s command -v parted` || { echo >&2 "Program parted not available. Aborting."; exit 1; }
+MKFSVFAT=`command -v mkfs.vfat` || MKFSVFAT=`sudo -s command -v mkfs.vfat` || { echo >&2 "Program mkfs.vfat not available. Aborting."; exit 1; }
+MKFSEXT3=`command -v mkfs.ext3` || MKFSEXT3=`sudo -s command -v mkfs.ext3` || { echo >&2 "Program mkfs.ext3 not available. Aborting."; exit 1; }
dd --help >/dev/null 2>&1 || { echo >&2 "Program dd not available. 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; }