diff --git a/towel.sh b/towel.sh index e98a907..4cb47c1 100755 --- a/towel.sh +++ b/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. # @@ -101,9 +131,9 @@ function tFileBrowser() { if [[ -d "${__SELECTION}" ]]; then # Was a directory selected? cd "${__SELECTION}" - elif [[ -f "${__SELECTION}" ]]; then + elif [[ -f "${__SELECTION}" ]]; then # Was a file selected? - if [[ ${__SELECTION} == *${__EXTENSION} ]]; then + if [[ ${__SELECTION} == *${__EXTENSION} ]]; then # Check if file has given extension if (whiptail --title "Confirm Selection" \ --yesno "Directory: ${__CURDIR}\n Filename: ${__SELECTION}" 0 0 \ @@ -143,7 +173,7 @@ function tFindPath() { local __RESULT=$1 local __SOURCE=$2 local __DIR= - + while [[ -h "${__SOURCE}" ]]; do __DIR="$( cd -P "$( dirname "${__SOURCE}" )" && pwd )" __SOURCE="$(readlink "${__SOURCE}")" @@ -204,12 +234,50 @@ function tGetTowelPath() { function tTrim() { local __RESULT=$1 local __VAR="${*:2}" - + # remove leading whitespace characters __VAR="${__VAR#"${__VAR%%[![:space:]]*}"}" # remove trailing whitespace characters __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} } @@ -219,5 +287,6 @@ function tTrim() { # 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