X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fscripts%2Ffunctions;h=22371ed1312a73d6d66655ee122ce462c47f8f40;hb=86a9657f40f1266ae61e021dc8bcadad55aa7301;hp=a2ad7f3d21804ba357fed2cdf272fd844e187191;hpb=54adb8bb5608e15ab944db970a1b287be28d7487;p=util-vserver.git diff --git a/util-vserver/scripts/functions b/util-vserver/scripts/functions index a2ad7f3..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