Skip to content
This repository
tree: 5c9fc132ce
Fetching contributors…

Cannot retrieve contributors at this time

executable file 258 lines (221 sloc) 34.381 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
#!/bin/bash

# audit system and check dependencies
# We aren't installing anything in this script, we're only checking your system for you and reporting back.

# logic
# 1 = installed, correct version.
# 0 = not installed.
# 2 = installed, wrong version.


# Requirements (versions required for yeoman)
reqnode=0.8.0
reqruby=1.8.7
reqcompass=0.12.1

# Check os
os=$(uname -s)

if [[ "$os" == "Darwin" ]]; then
  mac=1
elif [[ "$os" == "Linux" ]]; then
  linux=1
else
  echo "Windows is not officially supported, currently."
  exit 1
fi

# Dependency checks
     curlfile=$(command -v curl)
      gitfile=$(command -v git)
     rubyfile=$(command -v ruby)
     nodefile=$(command -v node)
      gemfile=$(command -v gem)
  compassfile=$(command -v compass)
     brewfile=$(command -v brew)
phantomjsfile=$(command -v phantomjs)
jpegturbofile=$(command -v jpegtran)
  optipngfile=$(command -v optipng)
    clangfile=$(command -v clang)
   yeomanfile=$(command -v yeoman)

# Check if installed.
check_set(){
  [[ -x "$1" ]] && echo 1 || echo 0
}


# This prints the ✘ in red,
# rest in bold.
sad_print(){
  printf '\e[31m%s\e[0m \e[1m%s\e[0m %s\n' "✘" "$1" "$2"
}

# This prints ✓ in green,
# rest in bold.
happy_print(){
  printf '\e[32m%s\e[0m \e[1m%s\e[0m %s\n' "✓" "$1" "$2"
}

# print extra descriptions for failure states
desc_print(){
  printf "\t%s \e[47m\e[0;35m%s\e[0m %s\n" "$1" "$2" "$3"
}

# audit \o/

audit() {
  echo ""
  echo "Before I can assist you I will need to confirm you have the necessary requirements. "
  echo ""
  echo "Below you will find the results of my short system audit:"

  if [[ $mac = 1 ]]; then
    # xcode cli test.
    cli=$(check_set $clangfile)

    # brew test.
    brew=$(check_set $brewfile)
  fi

  if [[ $linux = 1 ]]; then
    # curl test.
    curl=$(check_set $curlfile)
  fi

  # node test
  node=$(check_set $nodefile)
  if [[ $node == 1 ]]; then
    nodever=$(node -e 'console.log(process.versions.node);')
    # node version check
    if [[ "$nodever" < "$reqnode" ]]; then
      node=2
    fi
  fi

  # ruby test
  ruby=$(check_set $rubyfile)
  if [[ $ruby == 1 ]]; then
    rubyver=$(ruby -e 'print RUBY_VERSION')
    # ruby version check
    if [[ "$rubyver" < "$reqruby" ]]; then
      ruby=2
    fi
  fi


  # compass test
  compass=$(check_set $compassfile)
  if [[ $compass == 1 ]];then
    compassver=$(compass -qv)
    # compass version check
    if [[ "$compassver" < "$reqcompass" ]]; then
      compass=2
    fi
  fi


  git=$(check_set $gitfile)
  gem=$(check_set $gemfile)
  phantomjs=$(check_set $phantomjsfile)
  jpegturbo=$(check_set $jpegturbofile)
  optipng=$(check_set $optipngfile)
  yeoman=$(check_set $yeomanfile)

  # display results
  #
  # results logic
  # passes first
  # fails second

  echo ""

  # passes
  if [[ "$mac" = 1 ]]; then
    [ "$cli" -eq 1 ] && happy_print "Command Line Tools for Xcode" "check."
    [ "$brew" -eq 1 ] && happy_print "Homebrew" "check."
  fi

  if [[ "$linux" = 1 ]]; then
    [ "$curl" -eq 1 ] && happy_print "curl" "is present, phew."
  fi

  [ "$git" -eq 1 ] && happy_print "git" "smashing!"
  [ "$node" -eq 1 ] && happy_print "NodeJS" "check."
  [ "$ruby" -eq 1 ] && happy_print "ruby" "check."
  [ "$gem" -eq 1 ] && happy_print "RubyGems" "check."
  [ "$compass" -eq 1 ] && happy_print "Compass" "check."
  [ "$phantomjs" -eq 1 ] && happy_print "PhantomJS" "check."
  [ "$jpegturbo" -eq 1 ] && happy_print "jpegtran" "check."
  [ "$optipng" -eq 1 ] && happy_print "optipng" "check."
  [ "$yeoman" -eq 1 ] && happy_print "yeoman global npm module" "extraordinary!"

  # failures
  if [[ "$mac" = 1 ]]; then
    [ "$cli" -eq 0 ] && \
      sad_print "Command Line Tools for Xcode" "" && \
      desc_print "Visit http://stackoverflow.com/a/9329325/89484 for installation options."
    [ "$brew" -eq 0 ] && \
      sad_print "Homebrew" "" && \
      desc_print "Install Homebrew from the instructions at https://github.com/mxcl/homebrew/wiki/Installation " && \
      desc_print "For best results, after install, be sure to run" "brew doctor" "and follow the recommendations."
  fi

  if [[ "$linux" = 1 ]]; then
    [ "$curl" -eq 0 ] && sad_print "curl"
  fi

  [ "$git" -eq 0 ] && \
    sad_print "git" "" && \
    desc_print "Install through your package manager. " && \
    desc_print "For example, with homebrew:" "brew install git"
  [ "$node" -eq 0 ] && \
    sad_print "NodeJS" "" && \
    desc_print "I recommend you grab a fresh NodeJS install (>= 0.8.x) from http://nodejs.org/download/ "
  [ "$ruby" -eq 0 ] && \
    sad_print "ruby" "" && \
    desc_print "Check your ruby version is adequate with" "ruby -v" "(>= 1.8.7 required) and install http://www.ruby-lang.org/en/downloads/"
  [ "$gem" -eq 0 ] && \
    sad_print "RubyGems" "" && \
    desc_print "You'll acquire this with your ruby installation. "
  [ "$compass" -eq 0 ] && \
    sad_print "Compass" "" && \
    desc_print "is not installed: http://compass-style.org/install/ "
  [ "$phantomjs" -eq 0 ] && \
    sad_print "PhantomJS" "" && \
    desc_print "Follow instructions at http://phantomjs.org/download.html - the binary installs are quick! " && \
    desc_print "On Mac," "brew install phantomjs" "should do the trick."
  [ "$jpegturbo" -eq 0 ] && \
    sad_print "jpegtran" "" && \
    desc_print "On Mac," "brew install jpeg-turbo && brew link jpeg-turbo" "should do the trick. " && \
    desc_print "On Ubuntu," "sudo apt-get install libjpeg-turbo-progs" "should do the trick."
  [ "$optipng" -eq 0 ] && \
    sad_print "optipng" "" && \
    desc_print "On Mac," "brew install optipng" "will sort you out. " && \
    desc_print "On Ubuntu," "sudo apt-get install optipng" "should do the trick."
  [ "$yeoman" -eq 0 ] && \
    sad_print "yeoman" "" && \
    desc_print "You're missing yeoman!" "npm install -g yeoman" "will correct this atrocity. You may need sudo."



  echo ""
  echo "Areas I have not scored with a tick indicate I did not find your system satisfactory. You will need to correct these before I can be of service to you. Troubled? Consider reading http://goo.gl/XoyWI "
  echo ""
  printf "%s \e[47m\e[0;35m%s\e[0m %s\n" "Once all of my audit items are confirmed, we can begin. Type" "yeoman" "at your prompt to summon me."
  echo ""
}

# yeoman art.

art() {
  echo "                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
"
}

# function calls.
art
audit
Something went wrong with that request. Please try again.