2015-10-17 10:47:21 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-02-27 22:35:57 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2015-10-17 13:41:39 +02:00
|
|
|
|
2018-02-27 22:35:57 +01:00
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
2015-10-17 13:41:39 +02:00
|
|
|
|
2018-02-27 22:35:57 +01:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
2015-10-17 10:47:21 +02:00
|
|
|
|
2018-02-27 22:35:57 +01:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2015-10-17 10:47:21 +02:00
|
|
|
|
2018-02-27 22:35:57 +01:00
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
2015-10-17 13:41:39 +02:00
|
|
|
|
2018-02-27 22:35:57 +01:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2018-03-07 23:33:32 +01:00
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2018-02-27 22:35:57 +01:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2022-04-13 22:15:12 +02:00
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
|
|
password=$YNH_APP_ARG_PASSWORD
|
2022-04-14 00:33:50 +02:00
|
|
|
database=$YNH_APP_ARG_DATABASE
|
2021-07-22 15:51:13 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2015-10-17 13:41:39 +02:00
|
|
|
|
2022-04-13 20:36:45 +02:00
|
|
|
timezone="$(cat /etc/timezone)"
|
|
|
|
|
2018-02-27 22:35:57 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
2021-01-05 23:31:12 +01:00
|
|
|
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
2015-10-17 10:47:21 +02:00
|
|
|
|
2018-02-27 22:35:57 +01:00
|
|
|
final_path=/var/www/$app
|
2022-04-13 20:36:45 +02:00
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
2015-10-17 13:41:39 +02:00
|
|
|
|
2018-02-27 22:35:57 +01:00
|
|
|
# Register (book) web path
|
2021-01-05 23:31:12 +01:00
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
2015-10-17 13:41:39 +02:00
|
|
|
|
2018-02-27 22:35:57 +01:00
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2021-01-05 23:31:12 +01:00
|
|
|
ynh_script_progression --message="Storing installation settings..." --weight=1
|
2015-10-17 10:47:21 +02:00
|
|
|
|
2021-01-05 23:31:12 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
2022-04-14 00:33:50 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=database --value=$database
|
2019-09-25 22:51:37 +02:00
|
|
|
|
2022-04-13 20:36:45 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
2018-02-27 22:35:57 +01:00
|
|
|
#=================================================
|
2021-07-22 15:39:20 +02:00
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installing dependencies..." --weight=20
|
|
|
|
|
2022-04-14 00:33:50 +02:00
|
|
|
if [ $database == "pgsql" ]
|
|
|
|
then
|
2022-04-14 19:39:41 +02:00
|
|
|
pkg_dependencies="$pkg_dependencies $pgsql_pkg_dependencies"
|
2022-04-14 00:33:50 +02:00
|
|
|
fi
|
2021-07-22 15:39:20 +02:00
|
|
|
|
2022-04-14 00:33:50 +02:00
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
2015-10-17 13:41:39 +02:00
|
|
|
|
2021-06-15 22:16:38 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring system user..." --weight=1
|
|
|
|
|
|
|
|
# Create a system user
|
2021-07-22 16:18:37 +02:00
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
2021-06-15 22:16:38 +02:00
|
|
|
|
2022-04-14 00:33:50 +02:00
|
|
|
#=================================================
|
2022-04-18 20:10:22 +02:00
|
|
|
# CREATE A SQL DATABASE
|
2022-04-14 00:33:50 +02:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
db_user=$db_name
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
if [ $database == "pgsql" ]
|
|
|
|
then
|
2022-04-18 20:10:22 +02:00
|
|
|
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2
|
2022-04-14 00:33:50 +02:00
|
|
|
ynh_psql_test_if_first_run
|
|
|
|
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
|
2022-04-15 01:28:38 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd
|
2022-04-14 00:33:50 +02:00
|
|
|
else
|
2022-04-18 20:10:22 +02:00
|
|
|
ynh_script_progression --message="Creating a MySQL database..." --weight=2
|
2022-04-14 00:33:50 +02:00
|
|
|
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
|
2022-04-15 01:28:38 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd
|
2022-04-14 00:33:50 +02:00
|
|
|
fi
|
|
|
|
|
2018-02-27 22:35:57 +01:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2021-06-15 22:16:38 +02:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=1
|
2015-10-17 13:41:39 +02:00
|
|
|
|
2021-01-05 23:31:12 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2018-02-27 22:35:57 +01:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2021-01-05 23:31:12 +01:00
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
|
|
|
2022-04-13 20:36:45 +02:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
2015-10-17 13:41:39 +02:00
|
|
|
|
2018-02-27 22:35:57 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2021-01-05 23:31:12 +01:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
|
2015-10-17 13:41:39 +02:00
|
|
|
|
2021-01-05 23:31:12 +01:00
|
|
|
# Create a dedicated NGINX config
|
2018-02-27 22:35:57 +01:00
|
|
|
ynh_add_nginx_config
|
2015-10-17 13:41:39 +02:00
|
|
|
|
2018-02-27 22:35:57 +01:00
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2021-01-05 23:31:12 +01:00
|
|
|
ynh_script_progression --message="Configuring PHP-FPM..." --weight=2
|
2015-10-17 10:47:21 +02:00
|
|
|
|
2022-04-13 20:36:45 +02:00
|
|
|
# Create a dedicated PHP-FPM config
|
2021-11-14 15:32:27 +01:00
|
|
|
ynh_add_fpm_config
|
2021-01-05 23:31:12 +01:00
|
|
|
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
2015-10-17 13:41:39 +02:00
|
|
|
|
2021-01-05 23:55:50 +01:00
|
|
|
#=================================================
|
2022-04-13 20:36:45 +02:00
|
|
|
# SPECIFIC SETUP
|
2021-01-05 23:55:50 +01:00
|
|
|
#=================================================
|
2022-04-13 20:36:45 +02:00
|
|
|
# ADD A CONFIGURATION
|
2021-01-05 23:55:50 +01:00
|
|
|
#=================================================
|
2022-04-13 20:36:45 +02:00
|
|
|
ynh_script_progression --message="Adding a configuration file..." --weight=1
|
2021-01-05 23:55:50 +01:00
|
|
|
|
2022-04-14 00:33:50 +02:00
|
|
|
ynh_add_config --template="../conf/config.inc.php.$database" --destination="$final_path/galette/config/config.inc.php"
|
2021-01-05 23:55:50 +01:00
|
|
|
|
2022-04-13 20:36:45 +02:00
|
|
|
chmod 400 "$final_path/galette/config/config.inc.php"
|
|
|
|
chown $app:$app "$final_path/galette/config/config.inc.php"
|
|
|
|
|
2018-02-27 22:35:57 +01:00
|
|
|
#=================================================
|
2022-04-13 22:15:12 +02:00
|
|
|
# SETUP APPLICATION WITH CURL
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Setuping application with CURL..."
|
|
|
|
|
|
|
|
# Set the app as temporarily public for curl call
|
|
|
|
ynh_script_progression --message="Configuring SSOwat..."
|
|
|
|
# Making the app public for curl
|
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
|
|
|
|
|
|
|
# Installation with curl
|
|
|
|
ynh_script_progression --message="Finalizing installation..."
|
|
|
|
ynh_local_curl "/installer.php" "install_permsok=1"
|
2022-04-21 21:31:44 +02:00
|
|
|
ynh_local_curl "/installer.php" "install_type=i"
|
|
|
|
if [ $database == "pgsql" ]
|
2022-04-21 00:14:47 +02:00
|
|
|
then
|
|
|
|
ynh_local_curl "/installer.php" "install_dbtype=pgsql" "install_dbhost=localhost" "install_dbport=5432" "install_dbuser=$db_user" "install_dbpass=$db_pwd" "install_dbname=$db_name" "install_dbprefix=galette_"
|
|
|
|
else
|
|
|
|
ynh_local_curl "/installer.php" "install_dbtype=mysql" "install_dbhost=localhost" "install_dbport=3306" "install_dbuser=$db_user" "install_dbpass=$db_pwd" "install_dbname=$db_name" "install_dbprefix=galette_"
|
|
|
|
fi
|
2022-04-13 22:15:12 +02:00
|
|
|
ynh_local_curl "/installer.php" "install_dbperms_ok=1"
|
|
|
|
ynh_local_curl "/installer.php" "install_dbwrite_ok=1"
|
|
|
|
ynh_local_curl "/installer.php" "install_adminlogin=$admin" "install_adminpass=$password" "install_adminpass_verif=$password"
|
|
|
|
ynh_local_curl "/installer.php" "install_prefs_ok=1"
|
|
|
|
|
|
|
|
# Remove the public access
|
|
|
|
ynh_permission_update --permission="main" --remove="visitors"
|
|
|
|
|
2018-02-27 22:35:57 +01:00
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
2015-10-24 13:19:18 +02:00
|
|
|
|
2021-07-23 07:04:29 +02:00
|
|
|
chown $app $final_path/galette/config
|
2021-07-22 20:14:55 +02:00
|
|
|
chmod g+rwx $final_path/galette/config
|
2021-07-22 15:58:43 +02:00
|
|
|
|
2021-07-22 14:48:40 +02:00
|
|
|
for folder in attachments cache exports files imports logs photos templates_c tempimages
|
|
|
|
do
|
2021-07-22 20:14:55 +02:00
|
|
|
chown $app $final_path/galette/data/$folder
|
2021-07-23 07:04:29 +02:00
|
|
|
chmod g+rwx $final_path/galette/data/$folder
|
2021-07-22 15:58:43 +02:00
|
|
|
done
|
|
|
|
|
2022-04-13 20:36:45 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
2018-02-27 22:35:57 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2021-07-22 15:51:13 +02:00
|
|
|
ynh_script_progression --message="Configuring log rotation..." --weight=1
|
2018-02-27 22:35:57 +01:00
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
|
|
ynh_use_logrotate
|
|
|
|
|
2021-01-05 23:55:50 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2021-07-22 14:48:40 +02:00
|
|
|
ynh_script_progression --message="Configuring permissions..." --weight=1
|
2021-01-05 23:55:50 +01:00
|
|
|
|
2022-04-13 20:36:45 +02:00
|
|
|
# Make app public if necessary
|
2021-01-07 22:57:29 +01:00
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
2022-04-13 20:36:45 +02:00
|
|
|
# Everyone can access the app.
|
|
|
|
# The "main" permission is automatically created before the install script.
|
2021-07-22 15:51:13 +02:00
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
2021-01-07 22:57:29 +01:00
|
|
|
fi
|
2015-10-24 13:19:18 +02:00
|
|
|
|
2018-02-27 22:35:57 +01:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2021-01-05 23:31:12 +01:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
|
2015-10-24 13:19:18 +02:00
|
|
|
|
2021-01-05 23:31:12 +01:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2018-03-20 23:34:46 +01:00
|
|
|
|
2021-01-05 23:31:12 +01:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|