Last active
December 27, 2015 08:49
-
-
Save chernjie/7299330 to your computer and use it in GitHub Desktop.
find programme, if not found attempts to install
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 autoinst() | |
{ | |
declare -a _list=() | |
for i | |
do | |
command -v "$i" > /dev/null || _list[${#_list[@]}]="$i" | |
done | |
test ${#_list[@]} -eq 0 && return | |
local _attempt=0 | |
for j in brew apt-get port yum | |
do | |
command -v "$j" > /dev/null || continue | |
local _attempt=1 | |
sudo "$j" install -y -q ${_list[@]} | |
return | |
done | |
test $_attempt -eq 1 && | |
echo "Unable to find or install ${_list[@]}" >&2 && | |
exit 1 | |
} |
brew does not allow sudo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's a bug where if neither of
brew apt-get port yum
exists, it will skip with a exit code of0