Skip to content

Add prereq check #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: 6.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ sudo: required
# # We can't test stroom_services as it relies on a database that is not there
# #- STACK_NAME=stroom_services

services:
- docker
# Ensure we have an up to date version of docker. Using services:\n docker
# gives us an old version of docker.
addons:
apt:
packages:
- docker-ce

before_script: ./travis.before.sh

Expand Down
2 changes: 1 addition & 1 deletion bin/stack/lib/network_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ determine_host_address() {
# Code required to find IP address is different in MacOS
ip=$(ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk 'NR==1{print $2}')
else
ip=$(ip route get 1 |awk 'match($0,"src [0-9\\.]+") {print substr($0,RSTART+4,RLENGTH-4)}')
ip=$(ip route get 1 | awk 'match($0,"src [0-9\\.]+") {print substr($0,RSTART+4,RLENGTH-4)}')
fi

if [[ ! "${ip}" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
Expand Down
66 changes: 59 additions & 7 deletions bin/stack/lib/shell_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,52 @@
#
############################################################################

# Needed for ERR trap to work
set -o errtrace

# Array to hold any temp files to clean up at the end
# e.g. tempfiles+=( "$my_temp_file" )
tempfiles=( )

cleanup() {
rm -f "${tempfiles[@]}"
}

# Code adapted from https://stackoverflow.com/questions/64786/error-handling-in-bash
unexpected_error() {

local parent_lineno="$1"
local message="$2"
local code="${3:-1}"
if [[ -n "$message" ]] ; then
echo -e "${RED}Error${NC}: Script failed on or near line" \
"${BLUE}${parent_lineno}${NC}:" \
"${BLUE}${message}${NC}; exiting with status ${BLUE}${code}${NC}"
else
echo -e "${RED}Error${NC}: Script failed on or near line" \
"${BLUE}${parent_lineno}${NC};" \
"exiting with status ${BLUE}${code}${NC}"
fi
#dump_call_stack
exit "${code}"
}

ctrl_c() {
echo -e "Script cancelled by user!"
exit 1
}

trap 'unexpected_error ${LINENO}' ERR

trap ctrl_c SIGINT
trap ctrl_c SIGTERM

# Run cleanup on successful exit
trap cleanup 0

# Re-usable shell functions

setup_echo_colours() {
# Exit the script on any error
set -e

# shellcheck disable=SC2034
if [ "${MONOCHROME}" = true ]; then
RED=''
Expand Down Expand Up @@ -53,6 +93,18 @@ die () {
exit 1
}

debug() {
if [ "${IS_DEBUG_ENABLED}" = true ]; then
echo -e "${YELLOW}DEBUG${NC}: $*"
fi
}

debug_arguments() {
if [ "${IS_DEBUG_ENABLED}" = true ]; then
debug "${FUNCNAME[1]}() called with [$*]"
fi
}

test_for_bash_version_4() {
local -r bash_version="$(bash -c 'echo $BASH_VERSION')"
local -r bash_major_version="${bash_version:0:1}"
Expand Down Expand Up @@ -98,8 +150,8 @@ check_arg_count() {

if [[ "${actual_count}" -ne "${expected_count}" ]]; then
echo -e "${RED}ERROR${NC}:" \
"Incorrect number of arguments, expected ${expected_count}\n" \
"Arguments [$*]"
"Incorrect number of arguments, expected ${expected_count}." \
"Arguments passed: [${*:2}]"
dump_call_stack
exit 1
fi
Expand All @@ -112,8 +164,8 @@ check_arg_count_at_least() {

if [[ "${actual_count}" -lt "${expected_min_count}" ]]; then
echo -e "${RED}ERROR${NC}:" \
"Incorrect number of arguments, expected at least ${expected_min_count}\n" \
"Arguments [$*]"
"Incorrect number of arguments, expected at least ${expected_min_count}" \
"Arguments passed: [${*:2}]"
dump_call_stack
exit 1
fi
Expand Down
Loading