Added tTrimL, tTrimR, and tCheckPackages
This commit is contained in:
parent
e8fb6f57a8
commit
652877382d
1 changed files with 74 additions and 5 deletions
69
towel.sh
69
towel.sh
|
@ -24,6 +24,36 @@
|
|||
#
|
||||
|
||||
|
||||
#
|
||||
# Checks to see if listed packages have been installed.
|
||||
# Currently DEB packages only.
|
||||
#
|
||||
# Parameters:
|
||||
#
|
||||
# RESULT - Variable in which to return the packages that are missing.
|
||||
# VAR - List of packages to check, sparated by spaces.
|
||||
#
|
||||
function tCheckPackages() {
|
||||
local __RESULT=$1
|
||||
local __PACKAGES=${*:2}
|
||||
local __MISSING=
|
||||
local __P=
|
||||
|
||||
set +e
|
||||
for __P in ${__PACKAGES}; do
|
||||
dpkg-query -s ${__P} 2> /dev/null | grep -q ^"Status: install ok installed"$
|
||||
if [ "$?x" == "1x" ]; then
|
||||
__MISSING="${__MISSING} ${__P}"
|
||||
fi
|
||||
done
|
||||
set -e
|
||||
|
||||
tTrimL __MISSING "${__MISSING}"
|
||||
|
||||
eval $__RESULT=\${__MISSING}
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Escapes a given string so it's safe to write into an XML document.
|
||||
#
|
||||
|
@ -214,10 +244,49 @@ function tTrim() {
|
|||
}
|
||||
|
||||
|
||||
#
|
||||
# Removes whitespace from the beginning of a string.
|
||||
#
|
||||
# Parameters:
|
||||
#
|
||||
# RESULT - Variable in which to return the trimmed string.
|
||||
# VAR - String to trim.
|
||||
#
|
||||
function tTrimL() {
|
||||
local __RESULT=$1
|
||||
local __VAR="${*:2}"
|
||||
|
||||
# remove leading whitespace characters
|
||||
__VAR="${__VAR#"${__VAR%%[![:space:]]*}"}"
|
||||
|
||||
eval $__RESULT=\${__VAR}
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Removes whitespace from the end of a string.
|
||||
#
|
||||
# Parameters:
|
||||
#
|
||||
# RESULT - Variable in which to return the trimmed string.
|
||||
# VAR - String to trim.
|
||||
#
|
||||
function tTrimR() {
|
||||
local __RESULT=$1
|
||||
local __VAR="${*:2}"
|
||||
|
||||
# remove trailing whitespace characters
|
||||
__VAR="${__VAR%"${__VAR##*[![:space:]]}"}"
|
||||
|
||||
eval $__RESULT=\${__VAR}
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# We're a library. Don't run us.
|
||||
#
|
||||
if [ -z "${BASH_SOURCE[1]}" ]; then
|
||||
echo "This is a library. Include it into other scripts. Don't execute it."
|
||||
echo "Visit https://skunkworks.kangaroopunch.com/skunkworks/towel for more."
|
||||
exit 0
|
||||
fi
|
||||
|
|
Loading…
Add table
Reference in a new issue