Skip to content

Commit

Permalink
improve the setup.sh
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
szabgab committed Oct 31, 2024
1 parent 6163c61 commit 2431878
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
33 changes: 32 additions & 1 deletion tools/setup.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2431878

Please sign in to comment.