Added tTrimL, tTrimR, and tCheckPackages
This commit is contained in:
parent
e8fb6f57a8
commit
652877382d
1 changed files with 74 additions and 5 deletions
79
towel.sh
79
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.
|
# Escapes a given string so it's safe to write into an XML document.
|
||||||
#
|
#
|
||||||
|
@ -101,9 +131,9 @@ function tFileBrowser() {
|
||||||
if [[ -d "${__SELECTION}" ]]; then
|
if [[ -d "${__SELECTION}" ]]; then
|
||||||
# Was a directory selected?
|
# Was a directory selected?
|
||||||
cd "${__SELECTION}"
|
cd "${__SELECTION}"
|
||||||
elif [[ -f "${__SELECTION}" ]]; then
|
elif [[ -f "${__SELECTION}" ]]; then
|
||||||
# Was a file selected?
|
# Was a file selected?
|
||||||
if [[ ${__SELECTION} == *${__EXTENSION} ]]; then
|
if [[ ${__SELECTION} == *${__EXTENSION} ]]; then
|
||||||
# Check if file has given extension
|
# Check if file has given extension
|
||||||
if (whiptail --title "Confirm Selection" \
|
if (whiptail --title "Confirm Selection" \
|
||||||
--yesno "Directory: ${__CURDIR}\n Filename: ${__SELECTION}" 0 0 \
|
--yesno "Directory: ${__CURDIR}\n Filename: ${__SELECTION}" 0 0 \
|
||||||
|
@ -143,7 +173,7 @@ function tFindPath() {
|
||||||
local __RESULT=$1
|
local __RESULT=$1
|
||||||
local __SOURCE=$2
|
local __SOURCE=$2
|
||||||
local __DIR=
|
local __DIR=
|
||||||
|
|
||||||
while [[ -h "${__SOURCE}" ]]; do
|
while [[ -h "${__SOURCE}" ]]; do
|
||||||
__DIR="$( cd -P "$( dirname "${__SOURCE}" )" && pwd )"
|
__DIR="$( cd -P "$( dirname "${__SOURCE}" )" && pwd )"
|
||||||
__SOURCE="$(readlink "${__SOURCE}")"
|
__SOURCE="$(readlink "${__SOURCE}")"
|
||||||
|
@ -204,12 +234,50 @@ function tGetTowelPath() {
|
||||||
function tTrim() {
|
function tTrim() {
|
||||||
local __RESULT=$1
|
local __RESULT=$1
|
||||||
local __VAR="${*:2}"
|
local __VAR="${*:2}"
|
||||||
|
|
||||||
# remove leading whitespace characters
|
# remove leading whitespace characters
|
||||||
__VAR="${__VAR#"${__VAR%%[![:space:]]*}"}"
|
__VAR="${__VAR#"${__VAR%%[![:space:]]*}"}"
|
||||||
# remove trailing whitespace characters
|
# remove trailing whitespace characters
|
||||||
__VAR="${__VAR%"${__VAR##*[![:space:]]}"}"
|
__VAR="${__VAR%"${__VAR##*[![:space:]]}"}"
|
||||||
|
|
||||||
|
eval $__RESULT=\${__VAR}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# 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}
|
eval $__RESULT=\${__VAR}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,5 +287,6 @@ function tTrim() {
|
||||||
#
|
#
|
||||||
if [ -z "${BASH_SOURCE[1]}" ]; then
|
if [ -z "${BASH_SOURCE[1]}" ]; then
|
||||||
echo "This is a library. Include it into other scripts. Don't execute it."
|
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
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Reference in a new issue