Created
October 22, 2014 07:30
-
-
Save fwal/a52575313f75e1bdc86f to your computer and use it in GitHub Desktop.
Simple script for checking if certain commands are installed and prompt the user to install them if not
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
#! /bin/bash | |
function prompt { | |
while true; do | |
read -p "$1 is not installed. Do you wish to install it? [y/n]:" yn | |
case $yn in | |
[Yy]* ) return 1;; | |
[Nn]* ) return 0;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done | |
} | |
function check { | |
command -v $1 >/dev/null 2>&1 || { | |
if prompt "$2" $1; | |
then echo "Aborting..."; | |
else $3; | |
fi | |
} | |
} | |
# Syntax: check command display_name install_command | |
check /bin/foo "Foo" "echo Executing some install command :)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment