From 2431878b10da230b2800715a991ea7e016d9ed24 Mon Sep 17 00:00:00 2001 From: Gabor Szabo Date: Thu, 31 Oct 2024 06:42:21 +0200 Subject: [PATCH] improve the setup.sh * check if Rocket.toml exists and if it contains the required fields * update instructions to run bash * quote the output of pwd to handle pathes withs spaces in them Thanks to EzekTec in #73 --- docs/DEVELOPMENT.md | 2 +- tools/setup.sh | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md index 7a6ec76..4e18af1 100644 --- a/docs/DEVELOPMENT.md +++ b/docs/DEVELOPMENT.md @@ -4,7 +4,7 @@ * Start the Docker container that runs the SurrealDB ``` -./tools/setup.sh +bash tools/setup.sh ``` * Note: At the end of the development session you might want to stop the docker container. diff --git a/tools/setup.sh b/tools/setup.sh index 0ac7608..795fdf5 100755 --- a/tools/setup.sh +++ b/tools/setup.sh @@ -1,12 +1,43 @@ +set -e mkdir -p backup + +if [ ! -f Rocket.toml ]; then + echo "Rocket.toml not found!" + exit 1 +fi + database=$(cat Rocket.toml | grep "database_name " | cut -d'=' -f2 | sed 's/ //g' | sed 's/"//g') namespace=$(cat Rocket.toml | grep "database_namespace" | cut -d'=' -f2 | sed 's/ //g' | sed 's/"//g') username=$(cat Rocket.toml | grep "database_username" | cut -d'=' -f2 | sed 's/ //g' | sed 's/"//g') password=$(cat Rocket.toml | grep "database_password" | cut -d'=' -f2 | sed 's/ //g' | sed 's/"//g') + +if [ "$database" == "" ]; then + echo "database_name is missing from Rocket.toml" + exit 1 +fi + +if [ "$namespace" == "" ]; then + echo "database_namespace is missing from Rocket.toml" + exit 1 +fi + +if [ "$username" == "" ]; then + echo "database_username is missing from Rocket.toml" + exit 1 +fi + +if [ "$password" == "" ]; then + echo "database_password is missing from Rocket.toml" + exit 1 +fi + + echo $namespace echo $database #echo $username #echo $password + +set -x docker volume create my-surreal-db -docker run --detach --restart always --name surrealdb -p 127.0.0.1:8000:8000 --user root -v$(pwd):/external -v my-surreal-db:/database surrealdb/surrealdb:v2.0.4 start --user $username --pass $password --log trace file://database +docker run --detach --restart always --name surrealdb -p 127.0.0.1:8000:8000 --user root -v"$(pwd)":/external -v my-surreal-db:/database surrealdb/surrealdb:v2.0.4 start --user $username --pass $password --log trace file://database