Last active
November 16, 2022 20:21
-
-
Save gramian/7c3b621fbfc1eca6fa3ce901b6f7651c to your computer and use it in GitHub Desktop.
ArcadeDB initialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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