2015-03-25 23:03:51 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Useful functions in all scripts
|
|
|
|
|
|
|
|
# Make a list unique
|
|
|
|
function unique_list()
|
|
|
|
{
|
|
|
|
for d in $@
|
|
|
|
do
|
|
|
|
echo $d
|
|
|
|
done | sort | uniq
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_current_dir_is_src()
|
|
|
|
{
|
2015-06-08 14:49:10 +02:00
|
|
|
if [[ "${PWD}" == "${QP_ROOT}/src" ]]
|
2015-03-25 23:03:51 +01:00
|
|
|
then
|
|
|
|
return 0
|
|
|
|
else
|
2015-06-08 14:49:10 +02:00
|
|
|
echo "Current directory should be \$QP_ROOT/src"
|
2015-03-25 23:03:51 +01:00
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_current_dir_is_module()
|
|
|
|
{
|
2015-06-08 14:49:10 +02:00
|
|
|
# If the prefix ${QP_ROOT}/src/ can be removed from $PWD, it means that
|
|
|
|
# $PWD is somewhere below ${QP_ROOT}/src/ so it is a module.
|
|
|
|
# If the prefix ${QP_ROOT}/src/ can not be removed from $PWD, then
|
|
|
|
# "${PWD##${QP_ROOT}/src/}" == "$PWD".
|
2015-05-15 16:30:43 +02:00
|
|
|
|
2015-06-08 14:49:10 +02:00
|
|
|
if [[ "${PWD##${QP_ROOT}/src/}" != "$PWD" ]]
|
2015-03-25 23:03:51 +01:00
|
|
|
then
|
|
|
|
return 0
|
|
|
|
else
|
2015-05-15 16:30:43 +02:00
|
|
|
echo "You are not in a submodule"
|
2015-03-25 23:03:51 +01:00
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
}
|
2015-05-04 15:03:53 +02:00
|
|
|
|
2015-03-25 23:03:51 +01:00
|
|
|
# List of executables in the current directory
|
|
|
|
function ls_exe()
|
|
|
|
{
|
|
|
|
find . -perm /u+x -type f
|
|
|
|
}
|
|
|
|
|
|
|
|
function asksure() {
|
|
|
|
echo -n $@ "(Y/N) "
|
|
|
|
answer=w
|
|
|
|
while [[ $answer != [YyNn] ]]
|
|
|
|
do
|
|
|
|
read answer
|
|
|
|
[[ $answer = [Yy] ]] && retval=0 || retval=1
|
|
|
|
done
|
|
|
|
return $retval
|
|
|
|
}
|
|
|
|
|
|
|
|
function error()
|
|
|
|
{
|
|
|
|
echo "-------------------- Error --------------------"
|
|
|
|
printf "$@\n"
|
|
|
|
echo "-----------------------------------------------"
|
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ -z ${DEBUG} ]]
|
|
|
|
then
|
|
|
|
function info ()
|
|
|
|
{
|
|
|
|
:
|
|
|
|
}
|
|
|
|
else
|
|
|
|
function info ()
|
|
|
|
{
|
|
|
|
echo "$@"
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|