mirror of
https://github.com/YunoHost-Apps/pgadmin_ynh.git
synced 2024-09-03 19:56:38 +02:00
109 lines
2.9 KiB
Bash
109 lines
2.9 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
|
|
# 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 ./experimental_helper.sh
|
|
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
|
|
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
|
|
|
|
# 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
|
|
|
|
# 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"
|
|
|
|
#=================================================
|
|
# STANDARD MODIFICATIONS
|
|
#=================================================
|
|
|
|
# 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
|
|
PS1=""
|
|
source $final_path/bin/activate
|
|
ynh_replace_special_string "__ADMIN_PASSWORD__" "$admin_pwd" "../conf/setup.exp"
|
|
../conf/setup.exp "$final_path/bin/python2.7" "$final_path/lib/python2.7/site-packages/pgadmin4/setup.py" "$email"
|
|
|
|
# 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
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
|
|
# 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 uwsgi
|
|
systemctl restart uwsgi
|