Skip to content

Instantly share code, notes, and snippets.

@gramian
Last active November 16, 2022 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gramian/7c3b621fbfc1eca6fa3ce901b6f7651c to your computer and use it in GitHub Desktop.
Save gramian/7c3b621fbfc1eca6fa3ce901b6f7651c to your computer and use it in GitHub Desktop.
ArcadeDB initialization
#!/bin/bash
# Usage: ./init.sh localhost 2480 mydb root password myscript.sql
## Assign input commandline arguments
HOST=$1
PORT=$2
NAME=$3
USER=$4
PASS=$5
## Curry "curl" call
POST="curl --no-progress-meter --user ${USER}:${PASS} -X POST "
## Create Database
CRT=$(${POST} http://${HOST}:${PORT}/api/v1/create/${NAME} \
--retry-all-errors --retry 5 --retry-delay 1)
if [[ $CRT = *"\"error\":"* ]]; then
printf "init.sh: error when creating database.\n"
exit 1
fi
if [ -z "$6" ]; then
exit 0
fi
## Run Script (as Transaction)
SCRIPT="`cat $6`"
AID=$(${POST} http://${HOST}:${PORT}/api/v1/begin/${NAME} \
-I | grep "arcadedb-session-id")
CMD=$(${POST} http://${HOST}:${PORT}/api/v1/command/${NAME} \
-d "{ \"language\": \"sqlscript\", \"command\": \"${SCRIPT//$'\n'/}\"}" \
-H "Content-Type: application/json" \
-H "${AID} ")
CMT=$(${POST} http://${HOST}:${PORT}/api/v1/commit/${NAME} \
-H "${AID} ")
if [[ $CMD = *"\"error\":"* ]]; then
printf "init.sh: error when running script.\n"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment