X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fscripts%2Ffunctions;h=c874b14f7aec5e9dd29254c5ad3c6ce9f49a5195;hb=3373d861ddf49f31ae5bb8ce67a9769053d67860;hp=1b94ce464ed6df4ba0a1b1208a1b4c9006de0a1d;hpb=9775cd4fff7e44e02de1f5d962377457f433ba50;p=util-vserver.git diff --git a/util-vserver/scripts/functions b/util-vserver/scripts/functions index 1b94ce4..c874b14 100644 --- a/util-vserver/scripts/functions +++ b/util-vserver/scripts/functions @@ -15,29 +15,32 @@ # 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 - 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 -n "$_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 -n "$_fo_file" || { + echo "Can not find file for '$_fo_var'; aborting" exit 1 } >&2 - eval "$var=\"$file\"" + eval "$_fo_var=\"$_fo_file\"" } function findFile @@ -59,8 +62,8 @@ function findAndCopy shift findFile tmp "$@" - test "$tmp" -a -s "$tmp" || return 0 - cp -af "$tmp" "$dst" + test -n "$tmp" -a -s "$tmp" || return 0 + $_CP -af "$tmp" "$dst" } function getPhysicalDir @@ -68,17 +71,131 @@ function getPhysicalDir ( set -P && cd "$1" && pwd ) } +## Usage: logging +function logging +{ + if test -n "$_VS_LOGFILE"; then + echo "$@" >>"$_VS_LOGFILE" + else + echo "$@" + fi +} + +## Usage: warning +function warning +{ + if test -n "$_VS_ERRFILE"; then + echo "$@" >>"$_VS_ERRFILE" + else + echo "$@" >&2 + fi +} + +## Usage: panic +function panic +{ + if test -n "$_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 -n "$1" || return 1 + return 0 +} + +## Usage: colorize