Skip to content

Instantly share code, notes, and snippets.

@Saanch
Forked from JamieMason/is_installed.sh
Created August 2, 2017 09:44
Show Gist options
  • Save Saanch/13ddb0f0dea11b0886ea4ef383bb17d6 to your computer and use it in GitHub Desktop.
Save Saanch/13ddb0f0dea11b0886ea4ef383bb17d6 to your computer and use it in GitHub Desktop.

Revisions

  1. @JamieMason JamieMason revised this gist Feb 15, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion is_installed.sh
    Original file line number Diff line number Diff line change
    @@ -51,7 +51,7 @@ function echo_pass {
    # echo echo_if 1 "Passed"
    # echo echo_if 0 "Failed"
    function echo_if {
    if [ $1=1 ]; then
    if [ $1 == 1 ]; then
    echo_pass $2
    else
    echo_fail $2
  2. @JamieMason JamieMason revised this gist Feb 12, 2013. 1 changed file with 56 additions and 10 deletions.
    66 changes: 56 additions & 10 deletions is_installed.sh
    Original file line number Diff line number Diff line change
    @@ -1,29 +1,75 @@
    #!/bin/bash

    # Functions ==============================================

    # return 1 if global command line program installed, else 0
    # example
    # echo "node: $(program_is_installed node)"
    function program_is_installed {
    # set to 1 initially
    local return_=1
    # set to 0 if not found
    type $1 >/dev/null 2>&1 || { local return_=0; }
    # return value
    echo "$return_"
    }

    # return 1 if local npm package is installed at ./node_modules, else 0
    # example
    # echo "gruntacular : $(npm_package_is_installed gruntacular)"
    function npm_package_is_installed {
    # set to 1 initially
    local return_=1
    # set to 0 if not found
    ls node_modules | grep $1 >/dev/null 2>&1 || { local return_=0; }
    # return value
    echo "$return_"
    }

    # display a message in red with a cross by it
    # example
    # echo echo_fail "No"
    function echo_fail {
    # echo first argument in red
    printf "\e[31m✘ ${1}"
    # reset colours back to normal
    echo "\033[0m"
    }

    # display a message in green with a tick by it
    # example
    # echo echo_fail "Yes"
    function echo_pass {
    # echo first argument in green
    printf "\e[32m✔ ${1}"
    # reset colours back to normal
    echo "\033[0m"
    }

    # echo pass or fail
    # example
    # echo echo_if 1 "Passed"
    # echo echo_if 0 "Failed"
    function echo_if {
    if [ $1=1 ]; then
    echo_pass $2
    else
    echo_fail $2
    fi
    }

    # ============================================== Functions

    # command line programs
    echo "node : $(program_is_installed node)"
    echo "grunt : $(program_is_installed grunt)"
    echo "testacular : $(program_is_installed testacular)"
    echo "uglifyjs : $(program_is_installed uglifyjs)"
    echo "requirejs : $(program_is_installed r.js)"
    echo "lodash : $(program_is_installed lodash)"
    echo "gem : $(program_is_installed gem)"
    echo "node $(echo_if $(program_is_installed node))"
    echo "grunt $(echo_if $(program_is_installed grunt))"
    echo "testacular $(echo_if $(program_is_installed testacular))"
    echo "uglifyjs $(echo_if $(program_is_installed uglifyjs))"
    echo "requirejs $(echo_if $(program_is_installed r.js))"
    echo "lodash $(echo_if $(program_is_installed lodash))"
    echo "gem $(echo_if $(program_is_installed gem))"

    # local npm packages
    echo "grunt-shell : $(npm_package_is_installed grunt-shell)"
    echo "grunt-hashres : $(npm_package_is_installed grunt-hashres)"
    echo "gruntacular : $(npm_package_is_installed gruntacular)"
    echo "grunt-shell $(echo_if $(npm_package_is_installed grunt-shell))"
    echo "grunt-hashres $(echo_if $(npm_package_is_installed grunt-hashres))"
    echo "gruntacular $(echo_if $(npm_package_is_installed gruntacular))"
  3. @JamieMason JamieMason revised this gist Feb 12, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion is_installed.sh
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ echo "node : $(program_is_installed node)"
    echo "grunt : $(program_is_installed grunt)"
    echo "testacular : $(program_is_installed testacular)"
    echo "uglifyjs : $(program_is_installed uglifyjs)"
    echo "requirejs : $(program_is_installed requirejs)"
    echo "requirejs : $(program_is_installed r.js)"
    echo "lodash : $(program_is_installed lodash)"
    echo "gem : $(program_is_installed gem)"

  4. @JamieMason JamieMason revised this gist Feb 12, 2013. 1 changed file with 27 additions and 42 deletions.
    69 changes: 27 additions & 42 deletions is_installed.sh
    Original file line number Diff line number Diff line change
    @@ -1,44 +1,29 @@
    #!/bin/bash

    type gem >/dev/null 2>&1 || { install_gem=1; }
    type git >/dev/null 2>&1 || { install_git=1; }
    type ruby >/dev/null 2>&1 || { install_ruby=1; }
    type node >/dev/null 2>&1 || { install_node=1; }
    type brew >/dev/null 2>&1 || { install_brew=1; }
    type phantomjs >/dev/null 2>&1 || { install_phantomjs=1; }
    type i_do_not_exist >/dev/null 2>&1 || { install_i_do_not_exist=1; }

    if [ $install_gem ]
    then
    echo "gem required"
    fi

    if [ $install_git ]
    then
    echo "git required"
    fi

    if [ $install_ruby ]
    then
    echo "ruby required"
    fi

    if [ $install_node ]
    then
    echo "node required"
    fi

    if [ $install_brew ]
    then
    echo "brew required"
    fi

    if [ $install_phantomjs ]
    then
    echo "phantomjs required"
    fi

    if [ $install_i_do_not_exist ]
    then
    echo "i_do_not_exist required"
    fi
    # return 1 if global command line program installed, else 0
    function program_is_installed {
    local return_=1
    type $1 >/dev/null 2>&1 || { local return_=0; }
    echo "$return_"
    }

    # return 1 if local npm package is installed at ./node_modules, else 0
    function npm_package_is_installed {
    local return_=1
    ls node_modules | grep $1 >/dev/null 2>&1 || { local return_=0; }
    echo "$return_"
    }

    # command line programs
    echo "node : $(program_is_installed node)"
    echo "grunt : $(program_is_installed grunt)"
    echo "testacular : $(program_is_installed testacular)"
    echo "uglifyjs : $(program_is_installed uglifyjs)"
    echo "requirejs : $(program_is_installed requirejs)"
    echo "lodash : $(program_is_installed lodash)"
    echo "gem : $(program_is_installed gem)"

    # local npm packages
    echo "grunt-shell : $(npm_package_is_installed grunt-shell)"
    echo "grunt-hashres : $(npm_package_is_installed grunt-hashres)"
    echo "gruntacular : $(npm_package_is_installed gruntacular)"
  5. @JamieMason JamieMason revised this gist Feb 12, 2013. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions is_installed.sh
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,7 @@ type git >/dev/null 2>&1 || { install_git=1; }
    type ruby >/dev/null 2>&1 || { install_ruby=1; }
    type node >/dev/null 2>&1 || { install_node=1; }
    type brew >/dev/null 2>&1 || { install_brew=1; }
    type phantomjs >/dev/null 2>&1 || { install_phantomjs=1; }
    type i_do_not_exist >/dev/null 2>&1 || { install_i_do_not_exist=1; }

    if [ $install_gem ]
    @@ -32,6 +33,11 @@ then
    echo "brew required"
    fi

    if [ $install_phantomjs ]
    then
    echo "phantomjs required"
    fi

    if [ $install_i_do_not_exist ]
    then
    echo "i_do_not_exist required"
  6. @JamieMason JamieMason created this gist Feb 12, 2013.
    38 changes: 38 additions & 0 deletions is_installed.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    #!/bin/bash

    type gem >/dev/null 2>&1 || { install_gem=1; }
    type git >/dev/null 2>&1 || { install_git=1; }
    type ruby >/dev/null 2>&1 || { install_ruby=1; }
    type node >/dev/null 2>&1 || { install_node=1; }
    type brew >/dev/null 2>&1 || { install_brew=1; }
    type i_do_not_exist >/dev/null 2>&1 || { install_i_do_not_exist=1; }

    if [ $install_gem ]
    then
    echo "gem required"
    fi

    if [ $install_git ]
    then
    echo "git required"
    fi

    if [ $install_ruby ]
    then
    echo "ruby required"
    fi

    if [ $install_node ]
    then
    echo "node required"
    fi

    if [ $install_brew ]
    then
    echo "brew required"
    fi

    if [ $install_i_do_not_exist ]
    then
    echo "i_do_not_exist required"
    fi