X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fscripts%2Ffunctions;h=22371ed1312a73d6d66655ee122ce462c47f8f40;hb=e2770a5bfa046e037e4e4feddef4fd4750389033;hp=35d25e6df7e04e1744191c70a755bf192bfafc7e;hpb=de848176d34617bb2d80cc9bfac75c373f029118;p=util-vserver.git diff --git a/util-vserver/scripts/functions b/util-vserver/scripts/functions index 35d25e6..22371ed 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} @@ -60,7 +63,7 @@ function findAndCopy findFile tmp "$@" test "$tmp" -a -s "$tmp" || return 0 - cp -af "$tmp" "$dst" + $_CP -af "$tmp" "$dst" } function getPhysicalDir @@ -68,11 +71,125 @@ 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