mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
helpers2.1: remove a whole bunch of unused args in mongo helpers..
This commit is contained in:
parent
0273ee34b1
commit
9b6ccb7b1f
1 changed files with 115 additions and 185 deletions
|
@ -5,99 +5,29 @@
|
|||
# example: ynh_mongo_exec --command='db.getMongo().getDBNames().indexOf("wekan")'
|
||||
# example: ynh_mongo_exec --command="db.getMongo().getDBNames().indexOf(\"wekan\")"
|
||||
#
|
||||
# usage: ynh_mongo_exec [--user=user] [--password=password] [--authenticationdatabase=authenticationdatabase] [--database=database] [--host=host] [--port=port] --command="command" [--eval]
|
||||
# | arg: -u, --user= - The user name to connect as
|
||||
# | arg: -p, --password= - The user password
|
||||
# | arg: -d, --authenticationdatabase= - The authenticationdatabase to connect to
|
||||
# usage: ynh_mongo_exec [--database=database] --command="command"
|
||||
# | arg: -d, --database= - The database to connect to
|
||||
# | arg: -h, --host= - The host to connect to
|
||||
# | arg: -P, --port= - The port to connect to
|
||||
# | arg: -c, --command= - The command to evaluate
|
||||
# | arg: -e, --eval - Evaluate instead of execute the command.
|
||||
#
|
||||
#
|
||||
ynh_mongo_exec() {
|
||||
# ============ Argument parsing =============
|
||||
local -A args_array=( [u]=user= [p]=password= [a]=authenticationdatabase= [d]=database= [h]=host= [P]=port= [c]=command= [e]=eval )
|
||||
local user
|
||||
local password
|
||||
local authenticationdatabase
|
||||
local -A args_array=( [d]=database= [c]=command= )
|
||||
local database
|
||||
local host
|
||||
local port
|
||||
local command
|
||||
local eval
|
||||
ynh_handle_getopts_args "$@"
|
||||
user="${user:-}"
|
||||
password="${password:-}"
|
||||
authenticationdatabase="${authenticationdatabase:-}"
|
||||
database="${database:-}"
|
||||
host="${host:-}"
|
||||
port="${port:-}"
|
||||
eval=${eval:-0}
|
||||
# ===========================================
|
||||
|
||||
# If user is provided
|
||||
if [ -n "$user" ]
|
||||
then
|
||||
user="--username=$user"
|
||||
|
||||
# If password is provided
|
||||
if [ -n "$password" ]
|
||||
then
|
||||
password="--password=$password"
|
||||
fi
|
||||
|
||||
# If authenticationdatabase is provided
|
||||
if [ -n "$authenticationdatabase" ]
|
||||
then
|
||||
authenticationdatabase="--authenticationDatabase=$authenticationdatabase"
|
||||
else
|
||||
authenticationdatabase="--authenticationDatabase=admin"
|
||||
fi
|
||||
else
|
||||
password=""
|
||||
authenticationdatabase=""
|
||||
fi
|
||||
|
||||
# If host is provided
|
||||
if [ -n "$host" ]
|
||||
then
|
||||
host="--host=$host"
|
||||
fi
|
||||
|
||||
# If port is provided
|
||||
if [ -n "$port" ]
|
||||
then
|
||||
port="--port=$port"
|
||||
fi
|
||||
|
||||
# If eval is not provided
|
||||
if [ $eval -eq 0 ]
|
||||
then
|
||||
# If database is provided
|
||||
if [ -n "$database" ]
|
||||
then
|
||||
database="use $database"
|
||||
else
|
||||
database=""
|
||||
fi
|
||||
|
||||
mongosh --quiet --username $user --password $password --authenticationDatabase $authenticationdatabase --host $host --port $port <<EOF
|
||||
$database
|
||||
mongosh --quiet <<EOF
|
||||
use $database
|
||||
${command}
|
||||
quit()
|
||||
EOF
|
||||
else
|
||||
# If database is provided
|
||||
if [ -n "$database" ]
|
||||
then
|
||||
database="$database"
|
||||
else
|
||||
database=""
|
||||
fi
|
||||
|
||||
mongosh --quiet $database --username $user --password $password --authenticationDatabase $authenticationdatabase --host $host --port $port --eval="$command"
|
||||
mongosh --quiet --eval="$command"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -181,7 +111,7 @@ ynh_mongo_database_exists() {
|
|||
ynh_handle_getopts_args "$@"
|
||||
# ===========================================
|
||||
|
||||
if [ $(ynh_mongo_exec --command='db.getMongo().getDBNames().indexOf("'${database}'")' --eval) -lt 0 ]
|
||||
if [ $(ynh_mongo_exec --command='db.getMongo().getDBNames().indexOf("'${database}'")') -lt 0 ]
|
||||
then
|
||||
return 1
|
||||
else
|
||||
|
|
Loading…
Add table
Reference in a new issue