2017-11-14 16:05:26 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-01-31 16:08:58 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
|
2017-11-14 16:05:26 +01:00
|
|
|
# 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
|
2018-01-31 16:08:58 +01:00
|
|
|
source ./experimental_helper.sh
|
2017-11-14 16:05:26 +01:00
|
|
|
source ./_common.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
|
2017-11-16 21:10:21 +01:00
|
|
|
db_user="pgadmin"
|
2017-11-14 16:05:26 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2018-06-02 12:51:49 +02:00
|
|
|
# Get user email and check that the user exist
|
|
|
|
email=$(ynh_user_get_info $admin 'mail')
|
|
|
|
if [[ -z $email ]]
|
|
|
|
then
|
|
|
|
ynh_die "Can't get user email, check that the user exist or that the user have an email"
|
|
|
|
fi
|
|
|
|
|
2017-11-14 16:05:26 +01:00
|
|
|
# Build user password
|
|
|
|
db_pwd=$(ynh_string_random 30)
|
|
|
|
|
2017-11-16 21:10:21 +01:00
|
|
|
# Reserch an opened porf for pgadmin
|
|
|
|
port=$(ynh_find_port 5050)
|
|
|
|
|
2017-11-14 16:05:26 +01:00
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
ynh_app_setting_set $app domain $domain
|
|
|
|
ynh_app_setting_set $app path $path_url
|
2017-11-16 21:10:21 +01:00
|
|
|
ynh_app_setting_set $app pgadmin_port $port
|
2017-11-14 16:05:26 +01:00
|
|
|
ynh_app_setting_set $app admin $admin
|
|
|
|
ynh_app_setting_set $app admin_pwd "$admin_pwd"
|
2017-11-16 21:10:21 +01:00
|
|
|
ynh_app_setting_set $app db_user "$db_user"
|
|
|
|
ynh_app_setting_set $app db_pwd "$db_pwd"
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2018-01-31 16:08:58 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
|
2017-11-14 16:05:26 +01:00
|
|
|
# Install dependance
|
|
|
|
install_dependance
|
|
|
|
|
2017-11-16 21:10:21 +01:00
|
|
|
# Create user
|
|
|
|
ynh_system_user_create $pgadmin_user /var/lib/pgadmin
|
|
|
|
|
2017-11-14 16:05:26 +01:00
|
|
|
# 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
|
2017-11-16 21:10:21 +01:00
|
|
|
setup_dir
|
|
|
|
install_source
|
|
|
|
|
|
|
|
# CONFIGURE PGADMIN
|
|
|
|
config_pgadmin
|
|
|
|
|
|
|
|
# Config uwsgi
|
|
|
|
config_uwsgi
|
2017-11-14 16:05:26 +01:00
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
2017-11-16 21:10:21 +01:00
|
|
|
# initialisation sqlite database for pgadmin
|
|
|
|
chmod +x ../conf/setup.exp
|
2017-12-23 22:08:46 +01:00
|
|
|
PS1=""
|
2017-11-16 21:10:21 +01:00
|
|
|
source $final_path/bin/activate
|
2018-01-30 12:44:58 +01:00
|
|
|
ynh_replace_special_string "__ADMIN_PASSWORD__" "$admin_pwd" "../conf/setup.exp"
|
2018-11-07 19:30:34 +01:00
|
|
|
../conf/setup.exp "$final_path/bin/python3" "$final_path/lib/python$python_version/site-packages/pgadmin4/setup.py" "$email"
|
2017-11-14 16:05:26 +01:00
|
|
|
|
|
|
|
# POPULATE THE DATABASE
|
|
|
|
ynh_psql_test_if_first_run
|
2017-11-16 21:10:21 +01:00
|
|
|
su --command="psql -c\"CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSER CREATEDB CREATEROLE REPLICATION\"" postgres
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2017-11-16 21:10:21 +01:00
|
|
|
# Add Server In PGadmin database
|
2018-11-07 19:30:34 +01:00
|
|
|
ynh_replace_string "__PYTHON_VERSION__" "$python_version" config_database.py
|
|
|
|
$final_path/bin/python3 config_database.py "$db_user" "$db_pwd"
|
2017-11-16 21:10:21 +01:00
|
|
|
deactivate
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2018-01-31 16:08:58 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
|
2017-11-16 21:10:21 +01:00
|
|
|
# Set permission after initialisation
|
|
|
|
set_permission
|
2017-11-14 16:05:26 +01:00
|
|
|
|
|
|
|
# Restrict access to admin only
|
|
|
|
yunohost app addaccess --users=$admin $app
|
|
|
|
|
2017-11-16 21:10:21 +01:00
|
|
|
# Configuration de logrotate
|
|
|
|
ynh_use_logrotate /var/log/pgadmin
|
|
|
|
|
2018-03-15 23:33:57 +01:00
|
|
|
# reload uwsgi
|
2017-11-16 21:10:21 +01:00
|
|
|
systemctl restart uwsgi
|