From b7575319bfa05ea139cbce36bcbbababda58b008 Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Thu, 6 Feb 2014 11:24:31 +0100 Subject: [PATCH] run: Add 'check_installed' command to run env 'check_installed' takes a command name as argument and tries to call 'which' in order to find the command path. If that does not succeed, paths like '/sbin' are '/usr/sbin' searched. On success the absolute path of the command is returned, on failure 'exit' is called with an error message. Issue #1048 --- tool/run | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tool/run b/tool/run index 82c2251c7..ba0bf66e2 100755 --- a/tool/run +++ b/tool/run @@ -768,6 +768,35 @@ proc gdb { } { } +## +# Check if a shell command is installed +# +# \param command name of the command to search +# +# \return absolute path of command if cound, or exists if not +# +proc check_installed {command} { + if { [catch {set path [exec which $command]}] == 0} { + return $path + } + + set dir { /sbin /usr/sbin /usr/local/bin } + + foreach location $dir { + append location / $command + + if { [file exists $location] == 1} { + return $location + } + } + + puts stderr "Error: '$command' command could be not found. Please make sure to install the" + puts stderr " packet containing '$command', or make it avaiable in your PATH variable.\n" + + exit 1 +} + + ## # U-boot bootloader specific uImage #