diff --git a/scripts/_common.sh b/scripts/_common.sh index b71abe9..d531f63 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,10 +5,8 @@ #================================================= # dependencies used by the app -pkg_dependencies="mongodb mongodb-server mongo-tools" -pkg_dependencies_buster="mongodb-org mongodb-org-server mongodb-org-tools" -mongodb_stretch="mongodb" -mongodb_buster="mongod" +pkg_dependencies="" + nodejsversion=12.16.3 #================================================= diff --git a/scripts/install b/scripts/install index 06154b8..1e5da31 100755 --- a/scripts/install +++ b/scripts/install @@ -17,6 +17,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { + read -p "key" ynh_clean_check_starting } # Exit if an error occurs during the execution of the script @@ -78,14 +79,9 @@ ynh_script_progression --message="Installing dependencies..." ynh_install_nodejs --nodejs_version=$nodejsversion ynh_use_nodejs +ynh_mongo_install -if [ "$(lsb_release --codename --short)" = "buster" ]; then - ynh_install_extra_app_dependencies --repo="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" --package="$pkg_dependencies_buster" --key="https://www.mongodb.org/static/pgp/server-4.2.asc" - mongodb_servicename=$mongodb_buster -else - ynh_install_app_dependencies $pkg_dependencies - mongodb_servicename=$mongodb_stretch -fi +ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE A MONGODB DATABASE @@ -100,6 +96,7 @@ db_user=$db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name ynh_mongo_setup_db --db_user=$db_user --db_name=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) +read -p "key" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE diff --git a/scripts/remove b/scripts/remove index 5c7da5c..41092b0 100755 --- a/scripts/remove +++ b/scripts/remove @@ -63,11 +63,7 @@ ynh_script_progression --message="Removing dependencies..." ynh_remove_app_dependencies ynh_remove_nodejs -# Only remove the mongodb service if it is not installed. -if ! ynh_package_is_installed --package="mongodb" -then - yunohost service remove mongodb -fi +ynh_mongo_remove #================================================= # REMOVE APP MAIN DIR diff --git a/scripts/restore b/scripts/restore index 8baab5e..3dd1870 100644 --- a/scripts/restore +++ b/scripts/restore @@ -88,14 +88,9 @@ ynh_script_progression --message="Reinstalling dependencies..." # Define and install dependencies ynh_install_nodejs --nodejs_version=$nodejsversion ynh_use_nodejs +ynh_mongo_install -if [ "$(lsb_release --codename --short)" = "buster" ]; then - ynh_install_extra_app_dependencies --repo="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" --package="$pkg_dependencies_buster" --key="https://www.mongodb.org/static/pgp/server-4.2.asc" - mongodb_servicename=$mongodb_buster -else - ynh_install_app_dependencies $pkg_dependencies - mongodb_servicename=$mongodb_stretch -fi +ynh_install_app_dependencies $pkg_dependencies #================================================= # RESTORE THE MONGODB DATABASE diff --git a/scripts/upgrade b/scripts/upgrade index 9593102..790f73d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -188,14 +188,9 @@ ynh_script_progression --message="Upgrading dependencies..." ynh_remove_nodejs ynh_install_nodejs --nodejs_version=$nodejsversion ynh_use_nodejs +ynh_mongo_install -if [ "$(lsb_release --codename --short)" = "buster" ]; then - ynh_install_extra_app_dependencies --repo="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" --package="$pkg_dependencies_buster" --key="https://www.mongodb.org/static/pgp/server-4.2.asc" - mongodb_servicename=$mongodb_buster -else - ynh_install_app_dependencies $pkg_dependencies - mongodb_servicename=$mongodb_stretch -fi +ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER diff --git a/scripts/ynh_mongo_db b/scripts/ynh_mongo_db index dc2222a..b5743de 100644 --- a/scripts/ynh_mongo_db +++ b/scripts/ynh_mongo_db @@ -12,25 +12,26 @@ MONGO_CONFIG_BUSTER="/etc/mongod.conf" MONGO_REPO_BUSTER="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" MONGO_KEY_BUSTER="https://www.mongodb.org/static/pgp/server-4.2.asc" -# Evaluate a mongo command +# Execute a mongo command # -# example: ynh_mongo_eval_as --command='db.getMongo().getDBNames().indexOf("wekan")' -# example: ynh_mongo_eval_as --command="db.getMongo().getDBNames().indexOf(\"wekan\")" +# example: ynh_mongo_exec_as --command='db.getMongo().getDBNames().indexOf("wekan")' +# example: ynh_mongo_exec_as --command="db.getMongo().getDBNames().indexOf(\"wekan\")" # -# usage: ynh_mongo_eval_as [--user=user] [--password=password] [--authenticationdatabase=authenticationdatabase] [--database=database] [--host=host] [--port=port] --command="command" +# usage: ynh_mongo_exec_as [--user=user] [--password=password] [--authenticationdatabase=authenticationdatabase] [--database=database] [--host=host] [--port=port] --command="command" # | arg: -u, --user= - the user name to connect as # | arg: -p, --password= - the user password # | arg: -d, --authenticationdatabase= - the authenticationdatabase to connect to # | 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: -c, --command= - the command to execute +# | arg: -e, --eval - evaluate instead of execute the command. # # -ynh_mongo_eval_as() { +ynh_mongo_exec_as() { # Declare an array to define the options of this helper. local legacy_args=upadhPc - local -A args_array=( [u]=user= [p]=password= [a]=authenticationdatabase= [d]=database= [h]=host= [P]=port= [c]=command= ) + 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 @@ -38,6 +39,7 @@ ynh_mongo_eval_as() { local host local port local command + local eval # Manage arguments with getopts ynh_handle_getopts_args "$@" user="${user:-}" @@ -46,6 +48,7 @@ ynh_mongo_eval_as() { database="${database:-}" host="${host:-}" port="${port:-}" + eval=${eval:-0} # If user is provided if [ -n "$user" ] @@ -90,31 +93,49 @@ ynh_mongo_eval_as() { port="--port=$port" fi - mongo --quiet $user $password $authenticationdatabase $host $port <$MONGO_ROOT_PWD_FILE sleep 10 - ynh_mongo_eval_as --database=admin --command='db.createUser( { user: "'${MONGO_ROOT_USER}'", pwd: "'${mongo_root_password}'", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } );' + ynh_mongo_exec_as --database=admin --command='db.createUser( { user: "'${MONGO_ROOT_USER}'", pwd: "'${mongo_root_password}'", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } );' ynh_systemd_action --service_name=$MONGODB_SERVICENAME --action=stop # Enable access control @@ -342,4 +383,14 @@ ynh_mongo_install() { else ynh_install_app_dependencies $MONGO_DEPENDENCIES_STRETCH fi +} + + +ynh_mongo_remove() { + # Only remove the mongodb service if it is not installed. + if ! ynh_package_is_installed --package="mongodb" + then + yunohost service remove $MONGODB_SERVICENAME + # ynh_secure_remove --file=$MONGO_ROOT_PWD_FILE + fi } \ No newline at end of file