Files
dokku-mongo/subcommands/import
Jose Diaz-Gonzalez ddf428c035 Conform to function declaration standards
- declare desc variable
- declare all positional arguments
- set the cmd
- properly handle DOKKU_APP_NAME
2016-05-15 23:56:32 -04:00

25 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
mongo-import-cmd() {
declare desc="import a dump into the $PLUGIN_SERVICE service database"
local cmd="$PLUGIN_COMMAND_PREFIX:import" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1"
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$SERVICE"
SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
SERVICE_NAME="$(get_service_name "$SERVICE")"
PASSWORD="$(cat "$SERVICE_ROOT/PASSWORD")"
if [[ -t 0 ]]; then
dokku_log_fail "No data provided on stdin."
fi
docker exec -i "$SERVICE_NAME" bash -c "DIR=\$(mktemp -d) && tar xf - -C \"\$DIR\" && mongorestore -d $SERVICE -u \"$SERVICE\" -p \"$PASSWORD\" --authenticationDatabase \"$SERVICE\" \$(find \"\$DIR\" -mindepth 1 -maxdepth 1 -type d | head -n1) && rm -rf \"\$DIR\""
}
mongo-import-cmd "$@"