Refactored library functions
Minor cleanup to documentation, syntax, and consistency in general. Milestone: patch
This commit is contained in:
117
lib/verifiers.sh
117
lib/verifiers.sh
@@ -2,57 +2,65 @@
|
||||
|
||||
# Defines verification/validation functions.
|
||||
|
||||
# Checks for missing App Store applications.
|
||||
# Label: Verify App Store Applications
|
||||
# Description: Check for missing App Store applications.
|
||||
verify_app_store_applications() {
|
||||
printf "\nChecking App Store applications...\n"
|
||||
local applications=""
|
||||
|
||||
local applications="$(mas list)"
|
||||
printf "\n%s\n" "Checking App Store applications..."
|
||||
applications="$(mas list)"
|
||||
|
||||
while read line; do
|
||||
if [[ "$line" == "mas install"* ]]; then
|
||||
local application=$(printf "$line" | awk '{print $3}')
|
||||
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"
|
||||
printf "%s\n" "App Store check complete."
|
||||
}
|
||||
export -f verify_app_store_applications
|
||||
|
||||
# Verifies application exists.
|
||||
# Parameters: $1 (required) - The file name.
|
||||
# Label: Verify Application
|
||||
# Description: Verify application exists.
|
||||
# Parameters: $1 (required): 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"
|
||||
if [[ ! -e "$(get_install_path "$file_name")" ]]; then
|
||||
printf "%s\n" " - Missing: $file_name"
|
||||
fi
|
||||
}
|
||||
export -f verify_application
|
||||
|
||||
# Checks for missing applications suffixed by "APP_NAME" as defined in settings.sh.
|
||||
# Label: Verify Applications
|
||||
# Description: Check for missing applications suffixed by "APP_NAME" as defined in settings.
|
||||
verify_applications() {
|
||||
printf "\nChecking application software...\n"
|
||||
local file_names=""
|
||||
|
||||
printf "\n%s\n" "Checking application software..."
|
||||
|
||||
# Only use environment keys that end with "APP_NAME".
|
||||
local file_names=$(set | awk -F "=" '{print $1}' | grep ".*APP_NAME")
|
||||
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"
|
||||
printf "%s\n" "Application software check complete."
|
||||
}
|
||||
export -f verify_applications
|
||||
|
||||
# Checks for missing extensions suffixed by "EXTENSION_PATH" as defined in settings.sh.
|
||||
# Label: Verify Extensions
|
||||
# Description: Check for missing extensions suffixed by "EXTENSION_PATH" as defined in settings.
|
||||
verify_extensions() {
|
||||
printf "\nChecking application extensions...\n"
|
||||
local extensions=""
|
||||
|
||||
printf "\n%s\n" "Checking application extensions..."
|
||||
|
||||
# Only use environment keys that end with "EXTENSION_PATH".
|
||||
local extensions=$(set | awk -F "=" '{print $1}' | grep ".*EXTENSION_PATH")
|
||||
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
|
||||
@@ -60,36 +68,42 @@ verify_extensions() {
|
||||
verify_path "${!extension}"
|
||||
done
|
||||
|
||||
printf "Application extension check complete.\n"
|
||||
printf "%s\n" "Application extension check complete."
|
||||
}
|
||||
export -f verify_extensions
|
||||
|
||||
# Checks for missing Homebrew casks.
|
||||
# Label: Verify Homebrew Casks
|
||||
# Description: Check for missing Homebrew casks.
|
||||
verify_homebrew_casks() {
|
||||
local applications=""
|
||||
|
||||
printf "\nChecking Homebrew casks...\n"
|
||||
|
||||
local applications="$(brew list --casks)"
|
||||
applications="$(brew list --casks)"
|
||||
|
||||
while read line; do
|
||||
if [[ "$line" == "brew cask install"* ]]; then
|
||||
local application=$(printf "$line" | awk '{print $4}')
|
||||
application=$(printf "%s" "$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"
|
||||
printf "%s\n" "Homebrew cask check complete."
|
||||
}
|
||||
export -f verify_homebrew_casks
|
||||
|
||||
# Checks for missing Homebrew formulas.
|
||||
# Label: Verify Homebrew Formulas
|
||||
# Description: Check for missing Homebrew formulas.
|
||||
verify_homebrew_formulas() {
|
||||
local applications=""
|
||||
|
||||
printf "Checking Homebrew formulas...\n"
|
||||
|
||||
local applications="$(brew list --formulae)"
|
||||
applications="$(brew list --formulae)"
|
||||
|
||||
while read line; do
|
||||
if [[ "$line" == "brew install"* ]]; then
|
||||
local application=$(printf "$line" | awk '{print $3}')
|
||||
application=$(printf "%s" "$line" | awk '{print $3}')
|
||||
|
||||
# Exception: "gpg" is the binary but is listed as "gnugp".
|
||||
if [[ "$application" == "gpg" ]]; then
|
||||
@@ -100,80 +114,89 @@ verify_homebrew_formulas() {
|
||||
fi
|
||||
done < "$MAC_OS_CONFIG_PATH/bin/install_homebrew_formulas"
|
||||
|
||||
printf "Homebrew formula check complete.\n"
|
||||
printf "%s\n" "Homebrew formula check complete."
|
||||
}
|
||||
export -f verify_homebrew_formulas
|
||||
|
||||
# Verifies listed application exists.
|
||||
# Parameters: $1 (required) - The current application, $2 (required) - The application list.
|
||||
# Label: Verify Listed Application
|
||||
# Description: Verify listed application exists.
|
||||
# Parameters: $1 (required): Current application, $2 (required): Application list.
|
||||
verify_listed_application() {
|
||||
local application="$1"
|
||||
local applications="$2"
|
||||
|
||||
if [[ "${applications[*]}" != *"$application"* ]]; then
|
||||
printf " - Missing: $application\n"
|
||||
printf "%s\n" " - Missing: $application"
|
||||
fi
|
||||
}
|
||||
export -f verify_listed_application
|
||||
|
||||
# Verifies path exists.
|
||||
# Parameters: $1 (required) - The path.
|
||||
# Label: Verify Path
|
||||
# Description: Verify path exists.
|
||||
# Parameters: $1 (required): Path.
|
||||
verify_path() {
|
||||
local path="$1"
|
||||
|
||||
if [[ ! -e "$path" ]]; then
|
||||
printf " - Missing: $path\n"
|
||||
printf "%s\n" " - Missing: $path"
|
||||
fi
|
||||
}
|
||||
export -f verify_path
|
||||
|
||||
# Checks for missing Node packages.
|
||||
# Label: Verify Node Packages
|
||||
# Description: Check for missing Node packages.
|
||||
verify_node_packages() {
|
||||
printf "\nChecking Node packages...\n"
|
||||
printf "\n%s\n" "Checking Node packages..."
|
||||
|
||||
while read line; do
|
||||
if [[ "$line" == "npm "* ]]; then
|
||||
local package=$(printf "$line" | awk '{print $4}')
|
||||
local packages=($(npm list --global --depth=0 | grep "$package"))
|
||||
package=$(printf "$line" | awk '{print $4}')
|
||||
packages=($(npm list --global --depth=0 | grep "$package"))
|
||||
|
||||
verify_listed_application "$package" "${packages[*]}"
|
||||
fi
|
||||
done < "$MAC_OS_CONFIG_PATH/bin/install_node_packages"
|
||||
|
||||
printf "Node packages check complete.\n"
|
||||
printf "%s\n" "Node packages check complete."
|
||||
}
|
||||
export -f verify_node_packages
|
||||
|
||||
# Checks for missing Ruby gems.
|
||||
# Label: Verify Ruby Gems
|
||||
# Description: Check for missing Ruby gems.
|
||||
verify_ruby_gems() {
|
||||
local gems="$(gem list --no-versions)"
|
||||
local gems=""
|
||||
|
||||
printf "\nChecking Ruby gems...\n"
|
||||
printf "\n%s\n" "Checking Ruby gems..."
|
||||
|
||||
gems="$(gem list --no-versions)"
|
||||
|
||||
while read line; do
|
||||
if [[ "$line" == "gem install"* ]]; then
|
||||
local gem=$(printf "$line" | awk '{print $3}')
|
||||
gem=$(printf "%s" "$line" | awk '{print $3}')
|
||||
verify_listed_application "$gem" "${gems[*]}"
|
||||
fi
|
||||
done < "$MAC_OS_CONFIG_PATH/bin/install_ruby_gems"
|
||||
|
||||
printf "Ruby gems check complete.\n"
|
||||
printf "%s\n" "Ruby gems check complete."
|
||||
}
|
||||
export -f verify_ruby_gems
|
||||
|
||||
# Checks for missing Rust crates.
|
||||
# Label: Verify Rust Crates
|
||||
# Description: Check for missing Rust crates.
|
||||
verify_rust_crates() {
|
||||
printf "\nChecking Rust crates...\n"
|
||||
local crates=""
|
||||
|
||||
local crates="$(ls -A1 $HOME/.cargo/bin)"
|
||||
printf "\n%s\n" "Checking Rust crates..."
|
||||
|
||||
crates="$(ls -A1 $HOME/.cargo/bin)"
|
||||
|
||||
while read line; do
|
||||
if [[ "$line" == "cargo install"* ]]; then
|
||||
local crate=$(printf "$line" | awk '{print $3}')
|
||||
crate=$(printf "%s" "$line" | awk '{print $3}')
|
||||
verify_listed_application "$crate" "${crates[*]}"
|
||||
fi
|
||||
done < "$MAC_OS_CONFIG_PATH/bin/install_rust_crates"
|
||||
|
||||
printf "Rust crates check complete.\n"
|
||||
printf "%s\n" "Rust crates check complete."
|
||||
}
|
||||
export -f verify_rust_crates
|
||||
|
||||
Reference in New Issue
Block a user