Commit 836b9c83 authored by jackie / Andrea Ida Malkah Klaura's avatar jackie / Andrea Ida Malkah Klaura
Browse files

+ add getopts scaffold with simple mgmt commands

parent ecd79e89
......@@ -6,16 +6,86 @@ source src/tank.sh
source src/dashboard.sh
source src/webserver.sh
help_text () {
echo "Usage: $0 [-s HTTP_SCHEMA] COMMAND
Options:
-s HTTP_SCHEMA 'http' or 'https'. Overwrites automatic detection on prod/dev mode setting.
Only use this if you really know what you are doing. Data privacy may be at risk
-h Print this text and quit.
Use one of the following COMMANDs:
init Initialise the system before the first start. Does all the necessary setup.
start Start all AuRa components (should be initialised first)
stop Stop all AuRa components
cleanup Clear all containers and images (Attention: will destroy any saved data)
rebuild Rebuilds all component images
help Print this text. Similar to option -h.
"
}
help_text_and_quit () {
help_text
exit
}
# TODO: create getopts interface with options to init, run and stop services
while getopts ":hs:" opt; do
case $opt in
s)
if [ "$OPTARG" != "http" -a "$OPTARG" != "https" ]; then
echo "Invalid argument for option -s: $OPTARG" >&2
echo "Can only be either http or https." >&2
exit 1
fi
OVERWRITE_HTTP_SCHEMA="$OPTARG"
;;
h)
help_text_and_quit
;;
\?)
echo "Invalid option: -$OPTARG" >&2
echo
help_text_and_quit
;;
esac
done
COMMAND=${!OPTIND}
case $COMMAND in
init)
read_config
init_common
start_database_containers
# TODO: poll until databases are ready instead of sleeping 5s
echo "Sleeping for 5 seconds for the db containers to be fully set up"
sleep 5
init_steering
init_tank
init_dashboard
;;
start)
start_containers
read_config
init_webserver
start_webserver
;;
stop)
docker-compose down
;;
cleanup)
echo "TODO: implemented this!"
;;
rebuild)
echo "TODO: implemented this!"
;;
help)
help_text_and_quit
;;
*)
if [ -z "$COMMAND" ]; then
help_text_and_quit
fi
echo "Unknown command: $COMMAND"
exit 1
esac
init_common
start_database_containers
# TODO: poll until databases are ready instead of sleeping 5s
echo "Sleeping for 5 seconds for the db containers to be fully set up"
sleep 5
init_steering
init_tank
init_dashboard
start_containers
init_webserver
start_webserver
# init_common
# sources .env variables and initialises variables from aura-config.yaml
# and also write the global .env file for docker-compose
init_common () {
# read_config
# use the yq container to read all relevant settings from aura-config.yaml
# and set shell variables accordingly
read_config () {
echo "Reading required variables from aura-config.yaml"
MODE="$(docker run --rm -v "${PWD}"/aura-config.yaml:/workdir/aura-config.yaml mikefarah/yq eval '.aura.mode' aura-config.yaml)"
# by default https should be used except for local dev mode
......@@ -28,6 +28,11 @@ init_common () {
VUE_APP_TIMESLOT_FILTER_DEFAULT_NUMSLOTS="$(docker run --rm -v "${PWD}"/aura-config.yaml:/workdir/aura-config.yaml mikefarah/yq eval '.aura.dashboard.VUE_APP_TIMESLOT_FILTER_DEFAULT_NUMSLOTS' aura-config.yaml)"
VUE_APP_SHOW_THRESHOLD="$(docker run --rm -v "${PWD}"/aura-config.yaml:/workdir/aura-config.yaml mikefarah/yq eval '.aura.dashboard.VUE_APP_SHOW_THRESHOLD' aura-config.yaml)"
VUE_APP_TIMESLOT_FILTER_DEFAULT_DAYS="$(docker run --rm -v "${PWD}"/aura-config.yaml:/workdir/aura-config.yaml mikefarah/yq eval '.aura.dashboard.VUE_APP_TIMESLOT_FILTER_DEFAULT_DAYS' aura-config.yaml)"
}
# init_common
# write the global .env file for docker-compose with relevant variables
init_common () {
echo "Writing global .env for docker-compose"
echo "
STEERING_DB_PASS=$STEERING_DB_PASS
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment