2006-07-24 14:24:06 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# @P@/scripts/functions.sh
|
|
|
|
#
|
2006-07-25 18:50:00 +01:00
|
|
|
# (c)2006, @AUTHOR@, <@EMAIL@>.
|
|
|
|
# Released under the GNU GPLv2. See file COPYING or
|
|
|
|
# http://www.gnu.org/copyleft/gpl.html for details.
|
2006-07-24 14:24:06 +01:00
|
|
|
#
|
|
|
|
|
|
|
|
# Common functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Print a success message
|
|
|
|
print_success() {
|
|
|
|
if [ -z "${TERM}" -o "${TERM}" == "dumb" ]
|
|
|
|
then
|
|
|
|
echo -n " - "
|
|
|
|
else
|
|
|
|
(echo -n -e " \E[32m* "; tput sgr0)
|
|
|
|
fi
|
|
|
|
echo $*
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Print a failure message
|
|
|
|
print_failure() {
|
|
|
|
if [ -z "${TERM}" -o "${TERM}" == "dumb" ]
|
|
|
|
then
|
|
|
|
echo -n " *** "
|
|
|
|
else
|
|
|
|
(echo -n -e " \E[31m*** "; tput sgr0)
|
|
|
|
fi
|
|
|
|
echo $*
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# This function carries out a command, but reports its failure if
|
|
|
|
# necessary.
|
|
|
|
do_cmd() {
|
|
|
|
[ "${VERBOSE}" != "0" ] && echo "$@"
|
|
|
|
"$@"
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
|
|
|
print_failure "'$@' failed."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# This function carries out a command, but reports its failure if
|
|
|
|
# necessary.
|
|
|
|
do_cmd_redir() {
|
|
|
|
DEST=$1
|
|
|
|
shift
|
2006-07-24 14:49:31 +01:00
|
|
|
[ "${VERBOSE}" != "0" ] && echo "$@ >> ${DEST}"
|
2006-07-24 14:24:06 +01:00
|
|
|
"$@" >> ${DEST}
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
|
|
|
print_failure "'$@' failed."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
2006-07-25 18:50:00 +01:00
|
|
|
|
2006-07-25 19:19:59 +01:00
|
|
|
# kate: @KATE_MODELINE@
|
|
|
|
# vim: @VIM_MODELINE@
|