# Include for convenience log functions # Set _log_to_stderr to send messages to stderr as well, for logging : <<"END_OF_COPYRIGHT" Copyright (c) 2000-2012, CyberLeo All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of the source code must retain the above copyright notice, this list of conditions, and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILTY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. END_OF_COPYRIGHT if [ -z "${__log_sh_loaded}" ] then __log_sh_loaded=yes want ansi logf() { printf "${@}" [ -n "${_log_to_stderr}" ] && printf "${@}" >&2 return 0 } note() { printf " ${a_cyan}*${a_normal} " echo "${*}" [ -n "${_log_to_stderr}" ] && echo "* note: ${*}" >&2 return 0 } log() { printf " ${a_green}*${a_normal} " echo "${*}" [ -n "${_log_to_stderr}" ] && echo "* log: ${*}" >&2 return 0 } alias meh=log warn() { printf " ${a_yellow}*${a_normal} " echo "${*}" [ -n "${_log_to_stderr}" ] && echo "* warn: ${*}" >&2 return 0 } alias omg=warn err() { printf " ${a_red}*${a_normal} " echo "${*}" [ -n "${_log_to_stderr}" ] && echo "* err: ${*}" >&2 exit 1 } alias wtf=err chk() { _res=$? if [ $# -gt 0 ] then out=$("${@}") _res=$? fi if [ ${_res} -gt 0 ] then [ -n "${*}" ] && echo " ${a_red}*${a_normal} in '$(pwd)': cmd '${*}' failed with status ${_res}" [ -n "${out}" ] && printf " ${a_red}*${a_normal} Output:\n${out}\n" echo "" kill $$ fi } fi