X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fscripts%2Ffunctions;h=4a24bd57c4da5da1ce569678f5dffe52c6b4e318;hb=dfa40e043f50b3ed0f89cdec01d0655c94c1e12e;hp=e0a1f3fd3b4202c87186d015c68872d02a0a9c37;hpb=4bdcb4c266a7e84215692c17111eca5806e95a64;p=util-vserver.git diff --git a/util-vserver/scripts/functions b/util-vserver/scripts/functions index e0a1f3f..4a24bd5 100644 --- a/util-vserver/scripts/functions +++ b/util-vserver/scripts/functions @@ -21,6 +21,7 @@ _VS_ERRFILE= _VS_NEWLINE=' ' declare -r _VS_NEWLINE=${_VS_NEWLINE:0-1} +declare -r VS_ALLVSERVERS_ARGS=all,marked,unmarked,stopped,running function findObject { @@ -66,11 +67,46 @@ function findAndCopy $_CP -af "$tmp" "$dst" } +## Usage: isRegularFile [] +function isRegularFile +{ + test ${2:--f} "$1" || return 1 + + case $1 in + (*.rpmsave|*.rpmnew|*.rpmorig|*.cfsaved*|*.~*~) return 1;; + esac + + return 0 +} + function getPhysicalDir { ( set -P && cd "$1" && pwd ) } +## Usage:: isDirectoryEmpty [] +function isDirectoryEmpty +{ + ( + shopt -s dotglob || * + shopt -s nullglob || * + + ignore_lostfound=1 + test -z "$2" -o "$2" = 0 || ignore_lostfound= + + for i in "$1"/*; do + case "$i" in + (lost+found) + test "$ignore_lostfound" || exit 1 + ;; + (*) echo "$i"; exit 1 + esac + done + + exit 0 + ) +} + ## Usage: logging function logging { @@ -111,6 +147,14 @@ function execute exit 0 } + +## Usage: spawn +function spawn +{ + test -z "${DEBUG_EXEC:-}" || echo "$@" + test "${DEBUG_EXEC:-}" = noexec || "$@" +} + ## Usage: isNumber function isNumber { @@ -119,6 +163,22 @@ function isNumber return 0 } +## Usage: hasSubstring + +function hasSubstring +{ + local pat=$1 + local i + + shift + + for i; do + test x"${pat/*$i*/$i}" = x"$i" || continue + return 0 + done + + return 1 +} + ## Usage: colorize