From 3aea499672e807d70eb65c29011427e85ddefcd0 Mon Sep 17 00:00:00 2001 From: Brooke Kuhlmann Date: Sun, 21 Feb 2021 12:56:21 -0700 Subject: [PATCH] Refactored verifier functions to be alphabetically sorted Speeds up function lookup within the source code. --- lib/verifiers.sh | 158 +++++++++++++++++++++++------------------------ 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/lib/verifiers.sh b/lib/verifiers.sh index c1096bf..0e608c1 100644 --- a/lib/verifiers.sh +++ b/lib/verifiers.sh @@ -2,6 +2,85 @@ # Defines verification/validation functions. +# Checks for missing App Store applications. +verify_app_store_applications() { + printf "\nChecking App Store applications...\n" + + local applications="$(mas list)" + + while read line; do + if [[ "$line" == "mas install"* ]]; then + local application=$(printf "$line" | awk '{print $3}') + verify_listed_application "$application" "${applications[*]}" + fi + done < "$MAC_OS_CONFIG_PATH/bin/install_app_store" + + printf "App Store check complete.\n" +} +export -f verify_app_store_applications + +# Verifies application exists. +# Parameters: $1 (required) - The file name. +verify_application() { + local file_name="$1" + local install_path=$(get_install_path "$file_name") + + if [[ ! -e "$install_path" ]]; then + printf " - Missing: $file_name\n" + fi +} +export -f verify_application + +# Checks for missing applications suffixed by "APP_NAME" as defined in settings.sh. +verify_applications() { + printf "\nChecking application software...\n" + + # Only use environment keys that end with "APP_NAME". + local file_names=$(set | awk -F "=" '{print $1}' | grep ".*APP_NAME") + + # For each application name, check to see if the application is installed. Otherwise, skip. + for name in $file_names; do + verify_application "${!name}" + done + + printf "Application software check complete.\n" +} +export -f verify_applications + +# Checks for missing extensions suffixed by "EXTENSION_PATH" as defined in settings.sh. +verify_extensions() { + printf "\nChecking application extensions...\n" + + # Only use environment keys that end with "EXTENSION_PATH". + local extensions=$(set | awk -F "=" '{print $1}' | grep ".*EXTENSION_PATH") + + # For each extension, check to see if the extension is installed. Otherwise, skip. + for extension in $extensions; do + # Evaluate/extract the key (extension) value and pass it on for verfication. + verify_path "${!extension}" + done + + printf "Application extension check complete.\n" +} +export -f verify_extensions + +# Checks for missing Homebrew casks. +verify_homebrew_casks() { + printf "\nChecking Homebrew casks...\n" + + local applications="$(brew list --casks)" + + while read line; do + if [[ "$line" == "brew cask install"* ]]; then + local application=$(printf "$line" | awk '{print $4}') + verify_listed_application "$application" "${applications[*]}" + fi + done < "$MAC_OS_CONFIG_PATH/bin/install_homebrew_casks" + + printf "Homebrew cask check complete.\n" +} +export -f verify_homebrew_casks + # Checks for missing Homebrew formulas. verify_homebrew_formulas() { printf "Checking Homebrew formulas...\n" @@ -25,40 +104,6 @@ verify_homebrew_formulas() { } export -f verify_homebrew_formulas -# Checks for missing Homebrew casks. -verify_homebrew_casks() { - printf "\nChecking Homebrew casks...\n" - - local applications="$(brew list --casks)" - - while read line; do - if [[ "$line" == "brew cask install"* ]]; then - local application=$(printf "$line" | awk '{print $4}') - verify_listed_application "$application" "${applications[*]}" - fi - done < "$MAC_OS_CONFIG_PATH/bin/install_homebrew_casks" - - printf "Homebrew cask check complete.\n" -} -export -f verify_homebrew_casks - -# Checks for missing App Store applications. -verify_app_store_applications() { - printf "\nChecking App Store applications...\n" - - local applications="$(mas list)" - - while read line; do - if [[ "$line" == "mas install"* ]]; then - local application=$(printf "$line" | awk '{print $3}') - verify_listed_application "$application" "${applications[*]}" - fi - done < "$MAC_OS_CONFIG_PATH/bin/install_app_store" - - printf "App Store check complete.\n" -} -export -f verify_app_store_applications - # Verifies listed application exists. # Parameters: $1 (required) - The current application, $2 (required) - The application list. verify_listed_application() { @@ -71,51 +116,6 @@ verify_listed_application() { } export -f verify_listed_application -# Checks for missing applications suffixed by "APP_NAME" as defined in settings.sh. -verify_applications() { - printf "\nChecking application software...\n" - - # Only use environment keys that end with "APP_NAME". - local file_names=$(set | awk -F "=" '{print $1}' | grep ".*APP_NAME") - - # For each application name, check to see if the application is installed. Otherwise, skip. - for name in $file_names; do - verify_application "${!name}" - done - - printf "Application software check complete.\n" -} -export -f verify_applications - -# Verifies application exists. -# Parameters: $1 (required) - The file name. -verify_application() { - local file_name="$1" - local install_path=$(get_install_path "$file_name") - - if [[ ! -e "$install_path" ]]; then - printf " - Missing: $file_name\n" - fi -} -export -f verify_application - -# Checks for missing extensions suffixed by "EXTENSION_PATH" as defined in settings.sh. -verify_extensions() { - printf "\nChecking application extensions...\n" - - # Only use environment keys that end with "EXTENSION_PATH". - local extensions=$(set | awk -F "=" '{print $1}' | grep ".*EXTENSION_PATH") - - # For each extension, check to see if the extension is installed. Otherwise, skip. - for extension in $extensions; do - # Evaluate/extract the key (extension) value and pass it on for verfication. - verify_path "${!extension}" - done - - printf "Application extension check complete.\n" -} -export -f verify_extensions - # Verifies path exists. # Parameters: $1 (required) - The path. verify_path() {