You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
#!/bin/bash ## compose: no-hooks
if [ -z "$SERVICE_DATASTORE" ]; then echo "This script is meant to be run through 'compose' to work properly." >&2 exit 1 fi
version=0.1 usage="$exname [-h|--help] DBNAME" help=" USAGE:
$usage
DESCRIPTION:
Read stdin and content to related $CHARM_NAME service in the database DBNAME. If DBNAME is not provided, it'll take the default database from the ${DARKCYAN}mongo-database${NORMAL} relation of current service.
EXAMPLES:
$exname < foo.mongosh $exname mydb2 < foo.mongosh
"
dbname= output= while [ "$1" ]; do case "$1" in "--help"|"-h") print_help >&2 exit 0 ;; "--force"|"-f") force=yes ;; --*|-*) err "Unexpected optional argument '$1'" print_usage >&2 exit 1 ;; *) [ -z "$dbname" ] && { dbname=$1 ; shift ; continue ; } err "Unexpected positional argument '$1'" print_usage >&2 exit 1 ;; esac shift done
if [ -z "$dbname" ]; then if ! dbname=$(relation:get "$SERVICE_NAME":mongo-database dbname) || [ -z "$dbname" ]; then err "Couldn't retrieve information of ${DARKCYAN}mongo-database${NORMAL}'s relation." echo " You're database has maybe not yet be initialized." >&2 exit 1 fi fi
mongosh() { local dbname="$1" (
export SERVICE_NAME="$RELATION_TARGET_SERVICE" export SERVICE_DATASTORE="$DATASTORE/$SERVICE_NAME" DOCKER_BASE_IMAGE=$(service_ensure_image_ready "$SERVICE_NAME") export DOCKER_BASE_IMAGE
target_charm_path=$(charm.get_dir $RELATION_TARGET_CHARM) || exit 1
set +e
. "$target_charm_path/lib/common"
set -e ensure_db_docker_running
ddb "$dbname" ) }
mongosh "$dbname"
|