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=6735f2ee6e1c72b605dadf59fc3b2c5b438dc714;hpb=0436b01662c9f461544235dfc4d026ade36d3f1f;p=util-vserver.git diff --git a/util-vserver/scripts/functions b/util-vserver/scripts/functions index 6735f2e..22371ed 100644 --- a/util-vserver/scripts/functions +++ b/util-vserver/scripts/functions @@ -15,6 +15,13 @@ # 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} + function findObject { local mod=$1 @@ -46,41 +53,180 @@ function findDir findObject -d "$@" } +function findAndCopy +{ + local dst=$1 + test ! -s "$dst" || return 0 + + local tmp + shift + findFile tmp "$@" + + test "$tmp" -a -s "$tmp" || return 0 + $_CP -af "$tmp" "$dst" +} + 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