Last active
January 11, 2023 12:49
-
-
Save bumbummen99/b22f7e38b362999ffad08b7c628d09aa to your computer and use it in GitHub Desktop.
Helper script to determine if a given list of software is installed and available on the system.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/env bash | |
# Helper script to determine if a given list of software is installed and available on the system. | |
# The script will fail and output the missing software in case a software can not be found. | |
# | |
# Author: Patrick Henninger <[email protected]> | |
# License: GPLv3 | |
# Examples: | |
# ./installed.sh "pv rsync vim" && echo "Everything is installed" | |
# ... | |
# | |
# if ! installed.sh "pv rsync vim"; then# | |
# ... | |
# | |
# Configure | |
LIST="$@" | |
MISSING=() | |
function isInstalled() { | |
local SOFTWARE="$1" | |
# Check if SOFTWARE is installed | |
if command -v $SOFTWARE &> /dev/null; then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
# Iterate over provided software LIST | |
for ITEM in $LIST; do | |
# Check if the current ITEM is installed and available on this machine | |
if ! isInstalled "$ITEM"; then | |
# ITEM is not available, add it to the MISSING array | |
MISSING+=("$ITEM") | |
fi | |
done | |
# Check and fail in case we have missing software | |
if [ ${#MISSING[@]} -eq 0 ]; then | |
# No missing software, end execution with success | |
exit 0 | |
else | |
# Output all the missing software | |
echo "$MISSING" | |
# End execution with error | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment