Skip to content

Instantly share code, notes, and snippets.

@nu7hatch

nu7hatch/_utils.bash

Created Apr 15, 2013
Embed
What would you like to do?
Utilities for setup scripts.
# _utils.sh --- Utilities used across all the scripts.
set -e
set -o pipefail
# Prints spaces as a prefix to the command's output.
function prefixed {
sed -e "s/^/ /"
}
# Checks if command in the first agument is available
# in the host system.
#
# Usage:
#
# assert_command git
#
# Exits with code 1 if command is not available.
function assert_command {
cmd="$1"
command -v $cmd >/dev/null 2>&1 || {
echo "$cmd: Command required but not found. Aborting." >&2;
exit 1;
}
echo "$cmd: $(command -v $cmd)";
}
# Checks if all specified commands are available in the
# host system.
#
# Usage:
#
# assert_command git ruby mysql
#
# Exists with code 1 if any of given commands is not
# available in the system.
function assert_commands {
commands="$@"
for cmd in $commands; do
assert_command $cmd
done
}
# Checks if ruby version is correct.
#
# Usage:
#
# assert_ruby_version 1.9.3
#
# Command will fail if installed ruby version is lower
# than 1.9.3.
function assert_ruby_version {
version=$1
ruby -e 'RUBY_VERSION >= "$1" or exit 1' || exit $?
ruby -v
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment