2014-10-20 18:55:53 +02:00
|
|
|
#!/bin/bash
|
2015-10-27 16:03:21 +01:00
|
|
|
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2017-06-17 17:49:26 +02:00
|
|
|
# GENERIC START
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2017-06-05 13:11:48 +02:00
|
|
|
source _common.sh
|
2017-06-02 18:23:51 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
2017-06-17 17:49:26 +02:00
|
|
|
# MANAGE SCRIPT FAILURE
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
|
|
|
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_clean_setup () {
|
2018-06-28 22:05:35 +02:00
|
|
|
true
|
|
|
|
}
|
2017-06-17 17:49:26 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_abort_if_errors
|
2017-06-02 18:23:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
#REMOVEME? path=$YNH_APP_ARG_PATH
|
|
|
|
#REMOVEME? is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
#REMOVEME? language=$YNH_APP_ARG_LANGUAGE
|
|
|
|
#REMOVEME? admin=$YNH_APP_ARG_ADMIN
|
|
|
|
#REMOVEME? q2a_name=$YNH_APP_ARG_Q2A_NAME
|
2018-06-28 22:05:35 +02:00
|
|
|
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
|
2014-10-20 18:55:53 +02:00
|
|
|
|
2022-07-29 22:43:23 +02:00
|
|
|
email=$(ynh_user_get_info --username=$admin --key=mail)
|
|
|
|
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2017-06-17 17:49:26 +02:00
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Validating installation parameters..." --weight=2
|
2014-10-20 18:55:53 +02:00
|
|
|
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? install_dir=/var/www/$app
|
|
|
|
#REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder"
|
2017-08-28 23:55:51 +02:00
|
|
|
|
2017-06-17 17:49:26 +02:00
|
|
|
# Register (book) web path
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_webpath_register --app=$app --domain=$domain --path=$path
|
2014-10-20 18:55:53 +02:00
|
|
|
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Storing installation settings..." --weight=3
|
2015-10-27 16:03:21 +01:00
|
|
|
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=path --value=$path
|
2019-04-16 00:32:39 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=language --value=$language
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=admin --value=$admin
|
2017-06-02 18:23:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
2022-07-29 22:43:23 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Configuring system user..." --weight=5
|
2022-07-29 22:43:23 +02:00
|
|
|
|
|
|
|
# Create a system user
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
|
2022-07-29 22:43:23 +02:00
|
|
|
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2017-06-17 17:49:26 +02:00
|
|
|
# CREATE A MYSQL DATABASE
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Creating a MySQL database..." --weight=3
|
2018-06-28 22:05:35 +02:00
|
|
|
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
#REMOVEME? db_user=$db_name
|
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
#REMOVEME? ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
|
2017-06-02 18:23:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2021-02-22 11:52:00 +01:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=3
|
2017-06-02 18:23:51 +02:00
|
|
|
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir
|
2017-06-02 18:23:51 +02:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2023-03-29 16:46:28 +02:00
|
|
|
ynh_setup_source --dest_dir="$install_dir"
|
2017-06-02 18:23:51 +02:00
|
|
|
|
2023-03-29 16:46:28 +02:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:www-data "$install_dir"
|
2022-07-29 22:43:23 +02:00
|
|
|
|
2021-03-25 17:37:29 +01:00
|
|
|
#=================================================
|
2022-07-29 22:43:23 +02:00
|
|
|
# PHP-FPM CONFIGURATION
|
2021-03-25 17:37:29 +01:00
|
|
|
#=================================================
|
2022-07-29 22:43:23 +02:00
|
|
|
ynh_script_progression --message="Configuring PHP-FPM..." --weight=1
|
2021-03-25 17:37:29 +01:00
|
|
|
|
2022-07-29 22:43:23 +02:00
|
|
|
# Create a dedicated PHP-FPM config
|
|
|
|
ynh_add_fpm_config
|
2021-03-26 11:22:22 +01:00
|
|
|
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2021-02-22 11:52:00 +01:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=14
|
2017-06-02 18:23:51 +02:00
|
|
|
|
2020-08-02 15:41:28 +02:00
|
|
|
# Create a dedicated NGINX config
|
2018-05-27 15:44:58 +02:00
|
|
|
ynh_add_nginx_config
|
2017-06-02 18:23:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-07-29 22:43:23 +02:00
|
|
|
# SPECIFIC SETUP
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2022-07-29 22:43:23 +02:00
|
|
|
# DOWNLOAD AND UNPACK LDAP PLUGIN
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2022-07-29 22:43:23 +02:00
|
|
|
ynh_script_progression --message="Setting up LDAP plugin..." --weight=3
|
2017-06-02 18:23:51 +02:00
|
|
|
|
2022-07-29 22:43:23 +02:00
|
|
|
wget -O qa-ldap-login.zip https://github.com/zakkak/qa-ldap-login/archive/$ldap_login_commit.zip 2>&1
|
2018-06-28 22:05:35 +02:00
|
|
|
|
2023-03-29 16:46:28 +02:00
|
|
|
unzip qa-ldap-login.zip -d $install_dir/qa-plugin
|
|
|
|
mv $install_dir/qa-plugin/qa-ldap-login-$ldap_login_commit $install_dir/qa-plugin/qa-ldap-login
|
2022-07-29 22:43:23 +02:00
|
|
|
|
|
|
|
ynh_replace_string\
|
|
|
|
--match_string="require_once QA_INCLUDE_DIR . 'db/selects.php';"\
|
|
|
|
--replace_string="require_once QA_INCLUDE_DIR . 'db/selects.php';\r\n require_once QA_INCLUDE_DIR . '../qa-plugin/qa-ldap-login/qa-ldap-process.php';"\
|
2023-03-29 16:46:28 +02:00
|
|
|
--target_file="$install_dir/qa-include/pages/login.php"
|
2017-06-02 18:23:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
2021-02-22 11:52:00 +01:00
|
|
|
# DOWNLOAD TRANSLATIONS
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2021-02-22 11:52:00 +01:00
|
|
|
ynh_script_progression --message="Installing Translations..." --weight=6
|
|
|
|
|
|
|
|
### French
|
|
|
|
|
|
|
|
if [ $language == "fr" ]; then
|
2023-03-29 16:46:28 +02:00
|
|
|
git clone https://github.com/mrflos/q2a-lang-fr $install_dir/qa-lang/fr 2>&1
|
2021-02-22 11:52:00 +01:00
|
|
|
fi
|
2017-06-02 18:23:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-07-29 22:43:23 +02:00
|
|
|
# ADD A CONFIGURATION
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2022-07-29 22:43:23 +02:00
|
|
|
ynh_script_progression --message="Adding a configuration file..."
|
2017-06-02 18:23:51 +02:00
|
|
|
|
2023-03-29 16:46:28 +02:00
|
|
|
mv $install_dir/qa-config-example.php $install_dir/qa-config.php
|
|
|
|
mv $install_dir/.htaccess-example $install_dir/.htaccess
|
2018-06-28 22:05:35 +02:00
|
|
|
|
2023-03-29 16:46:28 +02:00
|
|
|
ynh_replace_string --match_string="your-mysql-username" --replace_string=$db_user --target_file="$install_dir/qa-config.php"
|
|
|
|
ynh_replace_string --match_string="your-mysql-password" --replace_string=$db_pwd --target_file="$install_dir/qa-config.php"
|
|
|
|
ynh_replace_string --match_string="your-mysql-db-name" --replace_string=$db_name --target_file="$install_dir/qa-config.php"
|
2017-06-02 18:23:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-06-17 17:49:26 +02:00
|
|
|
# SETUP APPLICATION WITH CURL
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2022-07-29 22:43:23 +02:00
|
|
|
ynh_script_progression --message="Setuping application with CURL..."
|
2017-06-02 18:23:51 +02:00
|
|
|
|
2017-06-17 17:49:26 +02:00
|
|
|
# Set the app as temporarily public for curl call
|
2021-02-22 11:52:00 +01:00
|
|
|
ynh_script_progression --message="Configuring SSOwat..." --weight=4
|
2021-01-06 13:31:32 +01:00
|
|
|
# Making the app public for curl
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_permission_update --permission="main" --add="visitors"
|
2017-06-02 18:23:51 +02:00
|
|
|
|
|
|
|
# Installation with curl
|
2021-02-22 11:52:00 +01:00
|
|
|
ynh_script_progression --message="Finalizing installation..." --weight=4
|
|
|
|
|
2022-07-29 22:43:23 +02:00
|
|
|
admin_temp_pass=$(ynh_string_random --length=10)
|
2021-03-26 18:13:57 +01:00
|
|
|
|
2021-02-22 11:52:00 +01:00
|
|
|
ynh_local_curl "/index.php?qa=install" "create=Set+up+the+Database+including+User+Management"
|
2021-03-26 18:13:57 +01:00
|
|
|
ynh_local_curl "/index.php?qa=install" "handle=$admin" "password=$admin_temp_pass" "email=$email" "super=Set+up+the+Super+Administrator"
|
2021-02-22 11:52:00 +01:00
|
|
|
ynh_local_curl_csrf "/index.php?qa=admin&qa_1=general"\
|
2021-03-26 18:20:59 +01:00
|
|
|
`myynh_urlencode "option_site_title=$q2a_name"`\
|
2023-03-29 16:46:28 +02:00
|
|
|
`myynh_urlencode "option_site_url=https://$domain$path"`\
|
2021-02-22 11:52:00 +01:00
|
|
|
"option_neat_urls=0"\
|
|
|
|
"option_site_language=$language"\
|
|
|
|
"option_site_theme=SnowFlat"\
|
|
|
|
"option_site_theme_mobile=SnowFlat"\
|
|
|
|
"option_site_text_direction=ltr"\
|
|
|
|
"option_tags_or_categories=tc"\
|
|
|
|
"dosaveoptions=1"\
|
|
|
|
"has_js=0"
|
|
|
|
|
2021-03-26 18:13:57 +01:00
|
|
|
ynh_replace_string --match_string="__ADMIN__" --replace_string="$admin" --target_file="../conf/ldap.sql"
|
|
|
|
ynh_replace_string --match_string="__ADMIN_EMAIL__" --replace_string="$email" --target_file="../conf/ldap.sql"
|
|
|
|
mysql -u $db_user -p${db_pwd} $db_name < ../conf/ldap.sql
|
2017-06-02 18:23:51 +02:00
|
|
|
|
2018-06-28 22:05:35 +02:00
|
|
|
# Remove the public access
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_permission_update --permission="main" --remove="visitors"
|
2018-06-28 22:05:35 +02:00
|
|
|
|
2017-06-02 18:23:51 +02:00
|
|
|
# Calculate and store the config file checksum into the app settings
|
2023-03-29 16:46:28 +02:00
|
|
|
ynh_store_file_checksum --file="$install_dir/qa-config.php"
|
|
|
|
ynh_store_file_checksum --file="$install_dir/.htaccess"
|
2017-06-02 18:23:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-06-17 17:49:26 +02:00
|
|
|
# SECURE FILES AND DIRECTORIES
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Set permissions to app files
|
2023-03-29 16:46:28 +02:00
|
|
|
chown -R $app: $install_dir
|
2017-06-02 18:23:51 +02:00
|
|
|
|
2023-03-29 16:46:28 +02:00
|
|
|
chmod o-rwx $install_dir
|
|
|
|
chown $app:www-data $install_dir
|
2021-04-08 15:04:33 +02:00
|
|
|
|
2021-02-22 11:52:00 +01:00
|
|
|
# Remove database initialization file
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_secure_remove --file="$install_dir/qa-include/qa-install.php"
|
2019-04-18 19:58:47 +02:00
|
|
|
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
2022-07-29 22:43:23 +02:00
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2017-06-02 18:23:51 +02:00
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Configuring permissions..." --weight=2
|
2017-06-02 18:23:51 +02:00
|
|
|
|
|
|
|
# Make app public if necessary
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? if [ $is_public -eq 1 ]
|
2017-06-02 18:23:51 +02:00
|
|
|
then
|
2020-02-08 17:16:25 +01:00
|
|
|
# Everyone can access the app.
|
|
|
|
# The "main" permission is automatically created before the install script.
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_permission_update --permission="main" --add="visitors"
|
2014-10-20 18:55:53 +02:00
|
|
|
fi
|
|
|
|
|
2020-02-08 17:16:25 +01:00
|
|
|
# Only the admin can access the admin panel of the app (if the app has an admin panel)
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_permission_create --permission="admin" --url="/index.php/admin" --allowed=$admin
|
2020-02-08 17:16:25 +01:00
|
|
|
|
2017-06-02 18:23:51 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=5
|
2019-02-10 15:02:38 +01:00
|
|
|
|
2023-03-29 16:46:28 +02:00
|
|
|
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
|
2019-02-10 15:02:38 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2021-02-22 11:52:00 +01:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|