Created
November 26, 2015 16:22
-
-
Save mejta/a923bd10840bb9e14d56 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/sh | |
| if [[ $EUID == 0 ]]; then | |
| echo "Refusing to run as sudo" 2>&1 | |
| exit 1 | |
| fi | |
| # check if library exists | |
| # lib exists if there is installed version in brew | |
| checkLib() { | |
| typeset ret_code | |
| ret_code=`brew ls --versions $1 2>&1 & echo $?` | |
| if [[ $ret_code != 0 ]]; then | |
| return 1 | |
| else | |
| return 0 | |
| fi | |
| } | |
| # install library with brew | |
| installLib() { | |
| typeset ret_code | |
| ret_code=`eval "brew install ${1}" 2>&1 & echo $?` | |
| if [[ $ret_code == 0 ]]; then | |
| return 1 | |
| else | |
| return 0 | |
| fi | |
| } | |
| # void main | |
| if ( checkLib $* ); then | |
| if ( installLib $* ); then | |
| echo "Installed \"$1\" for you :)" | |
| else | |
| echo "Fatal error, run \"brew install $1\" by yourself :(" | |
| fi | |
| else | |
| eval whereis $1 | |
| eval which $1 | |
| eval brew ls --versions $1 | |
| fi | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment