1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/question2answer_ynh.git synced 2024-09-03 20:16:07 +02:00
question2answer_ynh/scripts/install

230 lines
8.4 KiB
Text
Raw Normal View History

2014-10-20 18:55:53 +02:00
#!/bin/bash
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
#=================================================
2018-06-28 22:05:35 +02:00
ynh_clean_setup () {
true
}
2017-06-17 17:49:26 +02:00
# Exit if an error occurs during the execution of the script
2017-06-02 18:23:51 +02:00
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
language=$YNH_APP_ARG_LANGUAGE
2022-07-29 22:43:23 +02:00
admin=$YNH_APP_ARG_ADMIN
2021-03-26 18:20:59 +01:00
q2a_name=$YNH_APP_ARG_Q2A_NAME
2018-06-28 22:05:35 +02:00
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
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=2
2014-10-20 18:55:53 +02:00
2017-08-28 23:55:51 +02:00
final_path=/var/www/$app
2019-05-07 12:03:25 +02:00
test ! -e "$final_path" || 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
2019-04-16 00:32:39 +02:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2014-10-20 18:55:53 +02:00
2017-06-02 18:23:51 +02:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=3
2019-04-16 00:32:39 +02: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=language --value=$language
2022-07-29 22:43:23 +02:00
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
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=5
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
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
#=================================================
ynh_script_progression --message="Creating a MySQL database..." --weight=3
2018-06-28 22:05:35 +02:00
2019-05-07 12:03:25 +02:00
db_name=$(ynh_sanitize_dbid --db_name=$app)
2019-05-02 21:04:03 +02:00
db_user=$db_name
2019-04-16 00:32:39 +02:00
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
2019-05-02 21:04:03 +02:00
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
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=3
2017-06-02 18:23:51 +02:00
2019-04-16 00:32:39 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2017-06-02 18:23:51 +02:00
# Download, check integrity, uncompress and patch the source from app.src
2019-04-16 00:32:39 +02:00
ynh_setup_source --dest_dir="$final_path"
2017-06-02 18:23:51 +02:00
2022-07-29 22:43:23 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
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
2017-06-02 18:23:51 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
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
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
2022-07-29 22:43:23 +02:00
unzip qa-ldap-login.zip -d $final_path/qa-plugin
mv $final_path/qa-plugin/qa-ldap-login-$ldap_login_commit $final_path/qa-plugin/qa-ldap-login
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';"\
--target_file="$final_path/qa-include/pages/login.php"
2017-06-02 18:23:51 +02:00
#=================================================
# DOWNLOAD TRANSLATIONS
2017-06-02 18:23:51 +02:00
#=================================================
ynh_script_progression --message="Installing Translations..." --weight=6
### French
if [ $language == "fr" ]; then
2021-03-26 18:24:58 +01:00
git clone https://github.com/mrflos/q2a-lang-fr $final_path/qa-lang/fr 2>&1
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
mv $final_path/qa-config-example.php $final_path/qa-config.php
mv $final_path/.htaccess-example $final_path/.htaccess
2018-06-28 22:05:35 +02:00
ynh_replace_string --match_string="your-mysql-username" --replace_string=$db_user --target_file="$final_path/qa-config.php"
ynh_replace_string --match_string="your-mysql-password" --replace_string=$db_pwd --target_file="$final_path/qa-config.php"
ynh_replace_string --match_string="your-mysql-db-name" --replace_string=$db_name --target_file="$final_path/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
ynh_script_progression --message="Configuring SSOwat..." --weight=4
2021-01-06 13:31:32 +01:00
# Making the app public for curl
ynh_permission_update --permission="main" --add="visitors"
2017-06-02 18:23:51 +02:00
# Installation with curl
ynh_script_progression --message="Finalizing installation..." --weight=4
2022-07-29 22:43:23 +02:00
admin_temp_pass=$(ynh_string_random --length=10)
ynh_local_curl "/index.php?qa=install" "create=Set+up+the+Database+including+User+Management"
ynh_local_curl "/index.php?qa=install" "handle=$admin" "password=$admin_temp_pass" "email=$email" "super=Set+up+the+Super+Administrator"
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"`\
`myynh_urlencode "option_site_url=https://$domain$path_url"`\
"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"
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
2021-01-06 13:31:32 +01:00
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
ynh_store_file_checksum --file="$final_path/qa-config.php"
ynh_store_file_checksum --file="$final_path/.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
2022-07-29 22:43:23 +02:00
chown -R $app: $final_path
2017-06-02 18:23:51 +02:00
chmod o-rwx $final_path
chown $app:www-data $final_path
# Remove database initialization file
2022-07-29 22:43:23 +02:00
ynh_secure_remove --file="$final_path/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
#=================================================
ynh_script_progression --message="Configuring permissions..." --weight=2
2017-06-02 18:23:51 +02:00
# Make app public if necessary
if [ $is_public -eq 1 ]
then
2020-02-08 17:16:25 +01:00
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
2021-01-06 13:31:32 +01:00
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)
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
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=5
2019-02-10 15:02:38 +01:00
2019-04-18 19:58:47 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2019-02-10 15:02:38 +01:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last