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
|
2022-03-13 15:22:35 +01:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source experimental_helper.sh
|
|
|
|
source _common.sh
|
2017-11-14 16:05:26 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
}
|
2017-11-14 16:05:26 +01:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
#=================================================
|
2017-11-14 16:05:26 +01:00
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
2022-03-13 15:22:35 +01:00
|
|
|
#=================================================
|
|
|
|
|
2017-11-14 16:05:26 +01:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2020-12-12 15:02:45 +01:00
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2017-11-14 16:05:26 +01:00
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
2022-03-13 15:22:35 +01:00
|
|
|
admin_pwd=$YNH_APP_ARG_PASSWORD
|
|
|
|
|
2017-11-16 21:10:21 +01:00
|
|
|
db_user="pgadmin"
|
2022-03-13 15:22:35 +01:00
|
|
|
db_pwd=$(ynh_string_random --length 30)
|
2020-11-28 17:31:42 +01:00
|
|
|
app_version=$(ynh_app_upstream_version)
|
|
|
|
app_sub_version=$(echo $app_version | cut -d'-' -f2)
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
pgadmin_user="$app"
|
|
|
|
|
|
|
|
#=================================================
|
2017-11-14 16:05:26 +01:00
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
2022-03-13 15:22:35 +01:00
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
|
|
|
|
|
|
|
final_path=/opt/yunohost/$app
|
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
2017-11-14 16:05:26 +01:00
|
|
|
|
|
|
|
# Register (book) web path
|
2022-03-13 15:22:35 +01:00
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2018-06-02 12:51:49 +02:00
|
|
|
# Get user email and check that the user exist
|
2019-06-06 22:39:49 +02:00
|
|
|
email=$(ynh_user_get_info --username $admin --key 'mail')
|
2018-06-02 12:51:49 +02:00
|
|
|
if [[ -z $email ]]
|
|
|
|
then
|
2019-06-06 22:39:49 +02:00
|
|
|
ynh_die --message "Can't get user email, check that the user exist or that the user have an email"
|
2018-06-02 12:51:49 +02:00
|
|
|
fi
|
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
#=================================================
|
2017-11-14 16:05:26 +01:00
|
|
|
# STORE SETTINGS FROM MANIFEST
|
2022-03-13 15:22:35 +01:00
|
|
|
#=================================================
|
2019-06-06 22:39:49 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
2022-03-13 15:22:35 +01:00
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
|
|
|
ynh_app_setting_set --app=$app --key=admin --value=$admin
|
|
|
|
ynh_app_setting_set --app=$app --key=admin_pwd --value="$admin_pwd"
|
|
|
|
ynh_app_setting_set --app=$app --key=db_user --value="$db_user"
|
|
|
|
ynh_app_setting_set --app=$app --key=db_pwd --value="$db_pwd"
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2018-01-31 16:08:58 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
2022-03-13 15:22:35 +01:00
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2019-06-06 22:39:49 +02:00
|
|
|
ynh_script_progression --message="Installing dependencies..." --weight=7
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2019-06-06 22:39:49 +02:00
|
|
|
ynh_script_progression --message="Configuring system user..."
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create --username=$pgadmin_user --home_dir=$final_path
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Setting up source files..."
|
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2017-11-14 16:05:26 +01:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2019-06-06 22:39:49 +02:00
|
|
|
ynh_script_progression --message="Installing sources files..." --weight=10
|
2017-11-16 21:10:21 +01:00
|
|
|
setup_dir
|
|
|
|
install_source
|
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring NGINX web server..."
|
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# ...
|
|
|
|
#=================================================
|
|
|
|
|
2019-06-06 22:39:49 +02:00
|
|
|
ynh_script_progression --message="Configuring application..."
|
|
|
|
|
2017-11-16 21:10:21 +01:00
|
|
|
# CONFIGURE PGADMIN
|
|
|
|
config_pgadmin
|
|
|
|
|
|
|
|
# Config uwsgi
|
2019-06-06 22:39:49 +02:00
|
|
|
ynh_add_uwsgi_service 'pgadmin_user python_version'
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2019-06-06 22:39:49 +02:00
|
|
|
ynh_script_progression --message="Configuring sqlite database..."
|
|
|
|
|
2017-11-16 21:10:21 +01:00
|
|
|
# initialisation sqlite database for pgadmin
|
|
|
|
chmod +x ../conf/setup.exp
|
2020-07-29 23:14:43 +02:00
|
|
|
set +u;
|
2017-11-16 21:10:21 +01:00
|
|
|
source $final_path/bin/activate
|
2020-07-29 23:14:43 +02:00
|
|
|
set -u;
|
2019-06-06 22:39:49 +02:00
|
|
|
ynh_replace_special_string --match_string "__ADMIN_PASSWORD__" --replace_string "$admin_pwd" --target_file "../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
|
2019-06-06 22:39:49 +02:00
|
|
|
ynh_script_progression --message="Configuring Postgresql database..."
|
2017-11-14 16:05:26 +01:00
|
|
|
ynh_psql_test_if_first_run
|
2019-06-06 22:39:49 +02:00
|
|
|
ynh_psql_execute_as_root \
|
|
|
|
--sql "CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSER CREATEDB CREATEROLE REPLICATION"
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2017-11-16 21:10:21 +01:00
|
|
|
# Add Server In PGadmin database
|
2019-06-06 22:39:49 +02:00
|
|
|
ynh_replace_string --match_string "__PYTHON_VERSION__" --replace_string "$python_version" --target_file config_database.py
|
2018-11-07 19:30:34 +01:00
|
|
|
$final_path/bin/python3 config_database.py "$db_user" "$db_pwd"
|
2020-07-29 23:14:43 +02:00
|
|
|
set +u;
|
2017-11-16 21:10:21 +01:00
|
|
|
deactivate
|
2020-07-29 23:14:43 +02:00
|
|
|
set -u;
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
# Set permission after initialisation
|
|
|
|
ynh_script_progression --message="Protecting directory"
|
|
|
|
set_permission
|
|
|
|
|
2018-01-31 16:08:58 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2022-03-13 15:22:35 +01:00
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring log rotation..."
|
2018-01-31 16:08:58 +01:00
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
ynh_use_logrotate --logfile="/var/log/pgadmin"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=3
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name "uwsgi-app@$app.service" --action="restart" --line_match "WSGI app 0 \(mountpoint='[/[:alnum:]_-]*'\) ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/$app.log"
|
|
|
|
sleep 10
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring permissions..."
|
2017-11-14 16:05:26 +01:00
|
|
|
|
|
|
|
# Restrict access to admin only
|
2020-03-26 22:31:17 +01:00
|
|
|
ynh_permission_update --permission="main" --remove="all_users" --add=$admin
|
2017-11-14 16:05:26 +01:00
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
2017-11-16 21:10:21 +01:00
|
|
|
|
2022-03-13 15:22:35 +01:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2019-06-06 22:39:49 +02:00
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|