#!/bin/bash # colors used standouton=$(tput smso 2>/dev/null) standoutoff=$(tput rmso 2>/dev/null) redon=$(tput setaf 1 2>/dev/null)$(tput bold 2>/dev/null) redoff=$(tput sgr0 2>/dev/null) greenon=$(tput setaf 2 2>/dev/null)$(tput bold 2>/dev/null) greenoff=$(tput sgr0 2>/dev/null) yellowon=$(tput setaf 3 2>/dev/null)$(tput bold 2>/dev/null) yellowoff=$(tput sgr0 2>/dev/null) # if not empty, only error messages are printed quiet= # Prints a message. # $1 = message # $2... = attributes (can be empty) do_message() { local msg="$1" shift local options= while [ -n "$1" -a "${1#-}" != "$1" ] do options+=" $1" shift done local on= local off= if [ -n "$1" ]; then eval on=\"\$$1on\" eval off=\"\$$1off\" fi echo $options "$on$msg$off" } # Prints an error message prefixed by "Error: " and aborts script execution. # $1 = message to print to stderr error() { do_message "Error: $1" red >&2 [ $CLEANUP_LEVEL -eq 0 ] && exit 3 } # Prints a warning message prefixed by "Warning: ". # $1 = message to print to stderr warning() { do_message "Warning: $1" yellow >&2 } # Prints a normal message. # $1 = message to print # $2 = attribute (can be empty) message() { [ -n "$quiet" ] || do_message "$@" } has_option "-q" && quiet=1