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=f5987d8f58c6437302a01768e3abd4ba097374c2;hpb=743ce63629157f297f57137f34146c8dd0c86d78;p=util-vserver.git diff --git a/util-vserver/scripts/functions b/util-vserver/scripts/functions index f5987d8..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,12 +67,12 @@ function findAndCopy $_CP -af "$tmp" "$dst" } -## Usage: isRegularFile +## Usage: isRegularFile [] function isRegularFile { - test -f "$1" || return 1 + test ${2:--f} "$1" || return 1 - case $file in + case $1 in (*.rpmsave|*.rpmnew|*.rpmorig|*.cfsaved*|*.~*~) return 1;; esac @@ -83,6 +84,29 @@ 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 { @@ -139,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