rebuild-ontohub revision 2ee846646647982d31bd22bbb48bad2b98f13162
0N/A#!/bin/bash
431N/A
0N/Aabort_unless_invoker_installed() {
0N/A result="$(which invoker 2>&1)"
0N/A if [[ "$?" -ne "0" ]]; then
0N/A echo ">>> Invoker not installed, please install"
0N/A exit 1
0N/A fi
0N/A}
0N/A
0N/Ainitialize_new_invoker_instance() {
0N/A result="$(invoker list 2>&1)"
0N/A if [[ "$?" -eq "0" ]]; then
0N/A echo ">>> Invoker running, restarting..."
0N/A result=`invoker stop 2>&1`
0N/A else
0N/A echo ">>> Invoker not running, starting..."
0N/A fi
0N/A invoker start invoker.ini --daemon
0N/A}
0N/A
0N/Aexecute_or_die() {
0N/A cmd="$1"
0N/A execute_or_die_unless_match "$cmd" ""
0N/A}
0N/A
0N/Aexecute_or_die_unless_match() {
0N/A cmd="$1"
0N/A expression="$2"
0N/A echo ">>> Executing '$cmd'"
0N/A result="$($cmd 2>&1)"
0N/A state="$?"
0N/A if [[ "$state" -ne "0" ]]; then
460N/A if [[ -n "$expression" ]]; then
460N/A check_and_handle_result_text "$result" "$expression" "$cmd"
460N/A else
0N/A abort_cmd "$cmd"
0N/A fi
0N/A fi
0N/A}
0N/A
0N/Acheck_and_handle_result_text() {
0N/A result="$1"
0N/A expression="$2"
0N/A cmd="$3"
0N/A echo "$result" | grep -q "$expression"
0N/A matchstate="$?"
0N/A if [[ "$matchstate" -ne "0" ]]; then
0N/A abort_cmd "$cmd"
886N/A else
0N/A echo ">>> Failed to execute '$cmd', but ignoring the result."
0N/A fi
0N/A}
0N/A
0N/Aabort_cmd() {
0N/A cmd="$1"
0N/A echo ">>> Failed to execute '$cmd', aborting further commands."
0N/A exit 1
0N/A}
0N/A
0N/Arun_invoker="1"
0N/A
0N/Afor i in "$@"; do
0N/Acase $i in
0N/A -d|--download-fixtures)
0N/A export DOWNLOAD_FIXTURES=true
0N/A ;;
0N/A -r|--restart)
0N/A RESTART_INVOKER_ONLY=true
0N/A ;;
0N/A --no-invoker)
0N/A run_invoker="0"
0N/A ;;
0N/A *)
0N/A # unknown option
0N/A ;;
0N/A esac
0N/A shift
0N/Adone
0N/A
0N/Aif [[ "$run_invoker" -eq "1" ]]; then
0N/A abort_unless_invoker_installed
0N/A initialize_new_invoker_instance
0N/Afi
0N/A
0N/Aif [[ !($RESTART_INVOKER_ONLY) ]]; then
0N/A execute_or_die_unless_match "bundle exec rake elasticsearch:wipe" "Elasticsearch::Transport::Transport::Errors::NotFound"
0N/A execute_or_die "bundle exec rake db:migrate:clean"
0N/A execute_or_die "redis-cli flushdb"
0N/A execute_or_die "bundle exec rake git:compile_cp_keys"
0N/A execute_or_die "bundle exec rake db:seed"
0N/Afi
0N/A