Skip to content

Instantly share code, notes, and snippets.

@bumbummen99
Last active January 11, 2023 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bumbummen99/b22f7e38b362999ffad08b7c628d09aa to your computer and use it in GitHub Desktop.
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.
#/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 <privat@skyraptor.eu>
# 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