X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fscripts%2Ffunctions;h=9c3017446eb049e7d10a5a34d7f545e1442cb949;hb=cce0d3d757dba4c849b7b7e907e3e2cf26f8b76b;hp=947b4a4245b26fd722f31e9b495bb8e113e2d8a1;hpb=6fdd928b39e7453db43ec624d7d29fd58df5b66a;p=util-vserver.git diff --git a/util-vserver/scripts/functions b/util-vserver/scripts/functions index 947b4a4..9c30174 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,11 +53,138 @@ 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