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
This commit is contained in:
Sebastian Sumpf 2014-02-06 11:24:31 +01:00 committed by Norman Feske
parent 1c4c4d6961
commit b7575319bf
1 changed files with 29 additions and 0 deletions

View File

@ -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
#