2018-03-23 16:58:24 +00:00
|
|
|
#!/usr/bin/env bash
|
2018-04-16 18:45:46 +00:00
|
|
|
set -eu
|
2018-04-15 19:50:43 +00:00
|
|
|
set -o pipefail
|
|
|
|
set -o errtrace
|
2018-04-03 16:03:12 +00:00
|
|
|
shopt -s expand_aliases
|
|
|
|
[ "$(uname)" == "Darwin" ] && alias readlink="greadlink" || :
|
2018-03-23 16:58:24 +00:00
|
|
|
|
2018-05-08 10:44:38 +00:00
|
|
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
2018-06-15 13:18:46 +00:00
|
|
|
TFW_PATH="${TFW_PATH:-$SCRIPT_DIR/../..}"
|
|
|
|
|
2018-03-25 14:03:13 +00:00
|
|
|
BASEIMAGE_REPO="${BASEIMAGE_REPO:-baseimage-tutorial-framework}"
|
2018-06-15 13:18:46 +00:00
|
|
|
CHALLENGE_REPO="${CHALLENGE_REPO:-"$(basename "$(realpath "${SCRIPT_DIR}/..")")"}"
|
2018-03-23 16:58:24 +00:00
|
|
|
FRONTEND_REPO="${FRONTEND_REPO:-frontend-tutorial-framework}"
|
|
|
|
|
2018-06-15 13:18:46 +00:00
|
|
|
BASEIMAGE_PATH="${TFW_PATH}/${BASEIMAGE_REPO}"
|
|
|
|
CHALLENGE_PATH="${TFW_PATH}/${CHALLENGE_REPO}"
|
|
|
|
FRONTEND_PATH="${TFW_PATH}/${FRONTEND_REPO}"
|
2018-03-25 14:03:13 +00:00
|
|
|
|
2018-06-15 13:18:46 +00:00
|
|
|
source "${SCRIPT_DIR}/libhack/baseimage.sh"
|
|
|
|
source "${SCRIPT_DIR}/libhack/challenge.sh"
|
2018-06-15 14:03:26 +00:00
|
|
|
source "${SCRIPT_DIR}/libhack/frontend.sh"
|
2018-03-27 11:45:41 +00:00
|
|
|
|
2018-03-23 16:58:24 +00:00
|
|
|
|
2018-06-15 13:18:46 +00:00
|
|
|
start_challenge_and_frontend() {
|
2018-03-27 14:20:17 +00:00
|
|
|
trap 'exit' INT TERM
|
|
|
|
trap 'kill 0' EXIT
|
2018-06-15 14:03:26 +00:00
|
|
|
[[ "${RUN_FRONTEND:-1}" == "1" ]] && frontend::run &
|
2018-06-15 13:18:46 +00:00
|
|
|
[[ "${BUILD:-1}" == "1" ]] && challenge::build
|
|
|
|
challenge::run $@
|
2018-03-27 14:20:17 +00:00
|
|
|
wait
|
|
|
|
}
|
|
|
|
|
2018-04-19 15:01:59 +00:00
|
|
|
case ${1:-} in
|
2018-05-04 09:00:22 +00:00
|
|
|
start)
|
2018-06-15 13:18:46 +00:00
|
|
|
baseimage::build_if_exists
|
|
|
|
BUILD=1 RUN_FRONTEND=1 start_challenge_and_frontend ${@:2}
|
2018-05-04 09:00:22 +00:00
|
|
|
;;
|
2018-05-18 14:14:31 +00:00
|
|
|
run)
|
2018-06-15 13:18:46 +00:00
|
|
|
BUILD=0 RUN_FRONTEND=1 start_challenge_and_frontend ${@:2}
|
2018-05-18 14:14:31 +00:00
|
|
|
;;
|
2018-05-04 09:00:22 +00:00
|
|
|
startcontainer)
|
2018-06-15 13:18:46 +00:00
|
|
|
baseimage::build_if_exists
|
|
|
|
BUILD=1 RUN_FRONTEND=0 start_challenge_and_frontend ${@:2}
|
2018-05-04 09:00:22 +00:00
|
|
|
;;
|
2018-05-18 14:14:31 +00:00
|
|
|
runcontainer)
|
2018-06-15 13:18:46 +00:00
|
|
|
BUILD=0 RUN_FRONTEND=0 start_challenge_and_frontend ${@:2}
|
2018-05-18 14:14:31 +00:00
|
|
|
;;
|
2018-06-15 14:03:26 +00:00
|
|
|
runfrontend)
|
|
|
|
frontend::run
|
|
|
|
;;
|
2018-03-27 14:20:17 +00:00
|
|
|
buildtfw)
|
2018-06-15 13:18:46 +00:00
|
|
|
baseimage::build_if_exists
|
2018-03-27 14:07:59 +00:00
|
|
|
;;
|
|
|
|
build)
|
2018-06-15 13:18:46 +00:00
|
|
|
baseimage::build_if_exists
|
|
|
|
challenge::build
|
2018-03-27 14:07:59 +00:00
|
|
|
;;
|
2018-03-31 19:07:11 +00:00
|
|
|
buildwithfrontend)
|
2018-06-15 13:18:46 +00:00
|
|
|
baseimage::build_if_exists
|
|
|
|
challenge::build_with_frontend
|
2018-03-31 19:07:11 +00:00
|
|
|
;;
|
2018-05-04 09:00:22 +00:00
|
|
|
releasetfw)
|
2018-06-15 14:12:14 +00:00
|
|
|
[[ -d "$BASEIMAGE_PATH" ]] && baseimage::release || :
|
2018-05-04 09:00:22 +00:00
|
|
|
;;
|
2018-06-08 12:11:03 +00:00
|
|
|
builddocs)
|
2018-06-15 14:12:14 +00:00
|
|
|
[[ -d "$BASEIMAGE_PATH" ]] && baseimage::builddocs || :
|
2018-06-08 12:11:03 +00:00
|
|
|
;;
|
2018-03-27 14:07:59 +00:00
|
|
|
*)
|
2018-06-15 13:18:46 +00:00
|
|
|
echo "Usage: tfw.sh [COMMAND]"
|
|
|
|
echo " |--- start: build & run TFW challenge and Angular frontend"
|
|
|
|
echo " |--- run: run TFW challenge and Angular frontend"
|
|
|
|
echo " |--- startcontainer: build & run TFW challenge, container only"
|
|
|
|
echo " |--- runcontainer: run TFW challenge, container only"
|
2018-03-31 19:07:11 +00:00
|
|
|
echo " |--- buildtfw: build TFW baseimage"
|
2018-06-15 13:18:46 +00:00
|
|
|
echo " |--- build: build TFW baseimage and challenge"
|
|
|
|
echo " |--- buildwithfrontend: build TFW baseimage and challenge, include frontend in image"
|
2018-03-31 19:07:11 +00:00
|
|
|
echo " |--- releasetfw: tag TFW baseimage and push to upstream"
|
2018-06-08 12:11:03 +00:00
|
|
|
echo " |--- builddocs: build baseimage documentation (in docs/build/html)"
|
2018-03-27 14:07:59 +00:00
|
|
|
;;
|
|
|
|
esac
|