#!@l_bash@
##
##  arangomkdb.sh -- ArangoDB database creation utility
##

#   get information
if [ $# -ge 1 ]; then
    database="$1"; shift
else
    read -p "database: " -e database
fi
if [ $# -ge 1 ]; then
    username="$1"; shift
else
    read -p "username: " -e -i $database username
fi
if [ $# -ge 1 ]; then
    password="$1"; shift
else
    read -p "password: " -e -s password
    echo ""
fi
read -p "root password: " -e -s rootpw

#   generate the JavaScript code to create database
js="db._createDatabase(\"$username\", [], ["
js="$js { username: \"root\", passwd: \"$rootpw\" },"
js="$js { username: \"$username\", passwd: \"$password\" } ]);"

#   execute the JavaScript code
echo "$js" | \
@l_prefix@/bin/arangosh \
    --server.username root \
    --server.password "$rootpw"

