2017-11-14 16:05:26 +01:00
|
|
|
#!/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
|
2017-11-16 21:10:21 +01:00
|
|
|
source ./psql.sh
|
2017-11-14 16:05:26 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
# 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
|
|
|
|
../conf/setup.exp "$final_path/bin/python2.7" "$final_path/lib/python2.7/site-packages/pgadmin4/setup.py" "$admin@$domain" "$admin_pwd"
|
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
|
|
|
|
$final_path/bin/python2.7 config_database.py "$db_user" "$db_pwd"
|
|
|
|
deactivate
|
2017-11-14 16:05:26 +01:00
|
|
|
|
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
|
|
|
|
|
2017-11-14 16:05:26 +01:00
|
|
|
# RELOAD NGINX
|
|
|
|
systemctl reload nginx
|
2017-11-16 21:10:21 +01:00
|
|
|
systemctl restart uwsgi
|