X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fscripts%2Ffunctions;h=66c3bd333f1d35afc6f718d379132edc67c1232c;hb=e0b100caee0bc55f9654b834ebe4f952e85daee5;hp=35d25e6df7e04e1744191c70a755bf192bfafc7e;hpb=de848176d34617bb2d80cc9bfac75c373f029118;p=util-vserver.git diff --git a/util-vserver/scripts/functions b/util-vserver/scripts/functions index 35d25e6..66c3bd3 100644 --- a/util-vserver/scripts/functions +++ b/util-vserver/scripts/functions @@ -15,6 +15,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +_VS_LOGFILE= +_VS_ERRFILE= + _VS_NEWLINE=' ' declare -r _VS_NEWLINE=${_VS_NEWLINE:0-1} @@ -68,6 +71,120 @@ function getPhysicalDir ( set -P && cd "$1" && pwd ) } +## Usage: logging +function logging +{ + if test "$_VS_LOGFILE"; then + echo "$@" >>"$_VS_LOGFILE" + else + echo "$@" + fi +} + +## Usage: warning +function warning +{ + if test "$_VS_ERRFILE"; then + echo "$@" >>"$_VS_ERRFILE" + else + echo "$@" >&2 + fi +} + +## Usage: panic +function panic +{ + if test "$_VS_ERRFILE"; then + echo "$@" >>"$_VS_ERRFILE" + else + echo "$@" >&2 + fi + + exit 1 +} + +## Usage: execute +function execute +{ + test -z "${DEBUG_EXEC:-}" || echo "$@" + test "${DEBUG_EXEC:-}" = noexec || exec "$@" + exit 0 +} + +## Usage: isNumber +function isNumber +{ + local tmp + let tmp=$1+0 2>/dev/null || test -z "${1//0/}" -a "$1" || return 1 + return 0 +} + +## Usage: colorize