Skip to content

Instantly share code, notes, and snippets.

@awendt
Last active December 21, 2015 01:59
Show Gist options
  • Save awendt/6231589 to your computer and use it in GitHub Desktop.
Save awendt/6231589 to your computer and use it in GitHub Desktop.
#!/bin/bash
#===============================================================================
# FILE: infopark_system_check.sh
#
# USAGE: infopark_system_check.sh
#
# DESCRIPTION: Checks various system components on whether they are installed
# in a version needed to participate in the Infopark workshops.
#
# AUTHOR: Falk Köppe, falk.koeppe@infopark.de
# COMPANY: Infopark AG, Berlin
# VERSION: 0.0.1
# CREATED: 2013-06-29
#
# CHANGELOG:
# 2013-07-09
# * check if a ruby version manager is installed and hint to rbenv
# * check for JavaScript compiler libv8
# 2013-07-04
# * check for installed packages on Linux using dpkg
# * added notice to run rbenv rehash after installing bundler
# (Thanks @anne-schulz)
# 2013-06-29
# * initial version
#===============================================================================
# --------------------------------
# Define colors for output.
# --------------------------------
ccred=$(echo -e "\033[0;31m")
ccgreen=$(echo -e "\033[0;32m")
ccend=$(echo -e "\033[0m")
function version {
printf "%d%03d%03d%03d\n" `echo ${1//\./ }`;
}
function success {
echo -e $ccgreen '\xE2\x9C\x93' $ccend
}
function failure {
echo -e $ccred "\xC3\x97 $1" $ccend
}
function check () {
# version to check
local version="$1"
# required version
local required="$2"
# status of the version command
local status="$3"
# displayed label of the check
local label="$4"
# error message on failure
local error="$5"
echo -n $label
# check command status
if [[ $status -eq 0 ]]; then
# command exists, check required version if necessary
if [[ -z $required ]]; then
# no version required
success
elif [[ `version $version` -ge `version $required` ]]; then
# version matches required version
success
else
# version does not match required version
failure "($version)"
errors+=("$error")
fi
else
# command does not exist, means it does not seem to be installed properly
failure
errors+=("$error")
fi
}
echo '
Welcome to Infopark System Check
--------------------------------
Please make sure to have a green checkmark for all of the listed components to
successfully participate in the workshops. If you see a red cross start
installing the components from top to bottom and make sure to run the script
again.
You will find helpful information on failed components below the list. In case
you cannot resolve the issues, please feel free to contact us anytime at
support@infopark.de
--------------------------------
'
# --------------------------------------------
# Determine operating system
# --------------------------------------------
operating_system=$(uname -s)
echo "$operating_system detected..."
# --------------------------------------------
# Check operating system dependent tools
# --------------------------------------------
if [[ $operating_system = 'Darwin' ]]; then
# --------------------------------------
# Check Xcode with command line tools
# --------------------------------------
version=$(pkgutil --pkg-info=com.apple.pkg.DeveloperToolsCLI 2>/dev/null)
status=$?
required=''
label='Xcode with command line tools: '
error='Please install Xcode via the App Store, then open Xcode and install Command Line Tools over the preference menu.'
check "$version" "$required" "$status" "$label" "$error"
elif [[ $operating_system = 'Linux' ]]; then
echo '
We are using "dpkg" to check installed packages. If you are using a
different package manager, please make sure to use your package manager of
choice and check all packages listed as missing and install them if necessary.
'
# --------------------------------------
# Check installed packages
# --------------------------------------
# check libxslt-dev
version=$(dpkg -s libxslt-dev 2>/dev/null)
status=$?
required=''
label='libxslt-dev: '
error='Please install libxslt-dev package using "dpkg -i libxslt-dev".'
check "$version" "$required" "$status" "$label" "$error"
# check libxml2-dev
version=$(dpkg -s libxml2-dev 2>/dev/null)
status=$?
required=''
label='libxml2-dev: '
error='Please install libxml2-dev package using "dpkg -i libxml2-dev".'
check "$version" "$required" "$status" "$label" "$error"
# check openssl
version=$(dpkg -s openssl 2>/dev/null)
status=$?
required=''
label='openssl: '
error='Please install openssl package using "dpkg -i openssl".'
check "$version" "$required" "$status" "$label" "$error"
# check libssl-dev
version=$(dpkg -s libssl-dev 2>/dev/null)
status=$?
required=''
label='libssl-dev: '
error='Please install libssl-dev package using "dpkg -i libssl-dev".'
check "$version" "$required" "$status" "$label" "$error"
# check libreadline-dev
version=$(dpkg -s libreadline-dev 2>/dev/null)
status=$?
required=''
label='libreadline-dev: '
error='Please install libreadline-dev package using "dpkg -i libreadline-dev".'
check "$version" "$required" "$status" "$label" "$error"
fi
# --------------------------------
# Check Connectivity
# --------------------------------
version=$(ping -o google.com 2>/dev/null)
status=$?
required=''
label='Connectivity: '
error='Please make sure that you are connected to the internet.'
check "$version" "$required" "$status" "$label" "$error"
# --------------------------------
# Check Ruby version manager
# --------------------------------
version=$((rbenv --version || rvm --version) 2>/dev/null)
status=$?
required=''
label="Ruby version manager: "
error='Please refer to https://github.com/sstephenson/rbenv to install a Ruby Version Manager (recommended).'
check "$version" "$required" "$status" "$label" "$error"
# --------------------------------
# Check Ruby
# --------------------------------
version=$(ruby --version | cut -d' ' -f 2 | cut -dp -f 1 2>/dev/null)
status=$?
required='1.9.3'
label="Ruby $required: "
error='Please refer to https://github.com/sstephenson/rbenv to install a Ruby Version Manager (recommended) and Ruby in Version 1.9.3.'
check "$version" "$required" "$status" "$label" "$error"
# --------------------------------
# Check RubyGems
# --------------------------------
version=$(gem --version 2>/dev/null)
status=$?
required='1.8'
label='RubyGems: '
error='Please refer to http://docs.rubygems.org/read/chapter/3 to install RubyGems.'
check "$version" "$required" "$status" "$label" "$error"
# --------------------------------
# Check Git
# --------------------------------
version=$(git --version 2>/dev/null)
status=$?
required=''
label='Git: '
error='Please refer to http://git-scm.com/downloads to install git.'
check "$version" "$required" "$status" "$label" "$error"
# --------------------------------
# Check Bundler
# --------------------------------
version=$(bundle --version | cut -d' ' -f 3 2>/dev/null)
status=$?
required='1.3'
label='Bundler: '
error='Please run gem install bundler to install Bundler. If you are using rbenv to switch between multiple ruby versions, please run "rbenv rehash" afterwards.'
check "$version" "$required" "$status" "$label" "$error"
# --------------------------------
# Check Rails
# --------------------------------
version=$(gem list rails -i -v "~>3.2" 2>/dev/null)
status=$?
required=''
label='Rails 3.2.x: '
error='Please run "gem install rails -v 3.2.13" to install Ruby on Rails. Make sure to install the gem for Ruby version 1.9.3 if you are using a Ruby version manager.'
check "$version" "$required" "$status" "$label" "$error"
# --------------------------------
# Check libv8
# --------------------------------
version=$(gem list libv8 -i 2>/dev/null)
status=$?
required=''
label='JavaScript Compiler: '
error='Please run "gem install libv8" to install the JavaScript compiler. Make sure to install the gem for Ruby version 1.9.3 if you are using a Ruby version manager.'
check "$version" "$required" "$status" "$label" "$error"
# --------------------------------------
# Display errors and help information
# --------------------------------------
if [[ ! -z ${errors[@]} ]]; then
echo '
We encountered some errors. Please refer to the error messages below to fix
the issue. If you need help or found an error in our system check script,
please contact us at "support@infopark.de".
'
for error in "${errors[@]}"; do
echo " * ${error}"
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment