#!/bin/bash # IMPORT GENERIC HELPERS source /usr/share/yunohost/helpers # Exit if an error occurs during the execution of the script ynh_abort_if_errors # Import common cmd source ./_common.sh source ./psql.sh # RETRIEVE ARGUMENTS FROM THE MANIFEST domain=$YNH_APP_ARG_DOMAIN path_url=$(ynh_normalize_url_path $YNH_APP_ARG_PATH) admin=$YNH_APP_ARG_ADMIN admin_pwd=$YNH_APP_ARG_ADMIN_PASSWORD db_user="pgadmin" # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS test ! -e "$final_path" || ynh_die "This path already contains a folder" # Check web path availability ynh_webpath_available $domain $path_url # Register (book) web path ynh_webpath_register $app $domain $path_url # Build user password db_pwd=$(ynh_string_random 30) # Reserch an opened porf for pgadmin port=$(ynh_find_port 5050) # STORE SETTINGS FROM MANIFEST ynh_app_setting_set $app domain $domain ynh_app_setting_set $app path $path_url ynh_app_setting_set $app pgadmin_port $port ynh_app_setting_set $app admin $admin ynh_app_setting_set $app admin_pwd "$admin_pwd" ynh_app_setting_set $app db_user "$db_user" ynh_app_setting_set $app db_pwd "$db_pwd" # Install dependance install_dependance # Create user ynh_system_user_create $pgadmin_user /var/lib/pgadmin # DOWNLOAD, CHECK AND UNPACK SOURCE ynh_app_setting_set $app final_path $final_path # Download, check integrity, uncompress and patch the source from app.src setup_dir install_source # CONFIGURE PGADMIN config_pgadmin # Config uwsgi config_uwsgi # Create a dedicated nginx config ynh_add_nginx_config # initialisation sqlite database for pgadmin chmod +x ../conf/setup.exp source $final_path/bin/activate ../conf/setup.exp "$final_path/bin/python2.7" "$final_path/lib/python2.7/site-packages/pgadmin4/setup.py" "$admin@$domain" "$admin_pwd" # POPULATE THE DATABASE ynh_psql_test_if_first_run su --command="psql -c\"CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSER CREATEDB CREATEROLE REPLICATION\"" postgres # Add Server In PGadmin database $final_path/bin/python2.7 config_database.py "$db_user" "$db_pwd" deactivate # Set permission after initialisation set_permission # Restrict access to admin only yunohost app addaccess --users=$admin $app # Configuration de logrotate ynh_use_logrotate /var/log/pgadmin # RELOAD NGINX systemctl reload nginx systemctl restart uwsgi