X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fscripts%2Ffunctions;h=c8428b4aba7bde5469e18bd656b92acdb956bb3a;hb=dfb55b88d52fe085e24d2dcbfb5e32a6a580e1a0;hp=eb8e863e2619213e8a30d92bff09c3c5b7b2d2cd;hpb=5e65844d0c193527e61026b4a59d8d6d93de3a81;p=util-vserver.git diff --git a/util-vserver/scripts/functions b/util-vserver/scripts/functions index eb8e863..c8428b4 100644 --- a/util-vserver/scripts/functions +++ b/util-vserver/scripts/functions @@ -24,23 +24,23 @@ declare -r _VS_NEWLINE=${_VS_NEWLINE:0-1} function findObject { - local mod=$1 - local var=$2 - local file= - local i=X + local _fo_mod=$1 + local _fo_var=$2 + local _fo_file= + local _fo_i=X shift 2 - for i; do - test "$i" || continue - test ! $mod "$i" || { file=$i; break; } + for _fo_i; do + test "$_fo_i" || continue + test ! $_fo_mod "$_fo_i" || { _fo_file=$_fo_i; break; } done - test -z "$i" -o "$file" || { - echo "Can not find file for '$var'; aborting" + test -z "$_fo_i" -o "$_fo_file" || { + echo "Can not find file for '$_fo_var'; aborting" exit 1 } >&2 - eval "$var=\"$file\"" + eval "$_fo_var=\"$_fo_file\"" } function findFile @@ -63,7 +63,7 @@ function findAndCopy findFile tmp "$@" test "$tmp" -a -s "$tmp" || return 0 - cp -af "$tmp" "$dst" + $_CP -af "$tmp" "$dst" } function getPhysicalDir @@ -71,6 +71,7 @@ function getPhysicalDir ( set -P && cd "$1" && pwd ) } +## Usage: logging function logging { if test "$_VS_LOGFILE"; then @@ -80,6 +81,7 @@ function logging fi } +## Usage: warning function warning { if test "$_VS_ERRFILE"; then @@ -89,6 +91,7 @@ function warning fi } +## Usage: panic function panic { if test "$_VS_ERRFILE"; then @@ -100,6 +103,7 @@ function panic exit 1 } +## Usage: execute function execute { test -z "${DEBUG_EXEC:-}" || echo "$@" @@ -107,12 +111,85 @@ function execute 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