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
2024-01-24 11:21:00 +01:00

123 lines
4.5 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
email=$(ynh_user_get_info --username=$admin --key=mail)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=3
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
if [ $language == "fr" ]; then
ynh_setup_source --dest_dir="$install_dir/qa-lang/fr" --source_id="ldap"
fi
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring PHP-FPM..." --weight=1
# Create a dedicated PHP-FPM config
ynh_add_fpm_config
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# DOWNLOAD AND UNPACK LDAP PLUGIN
#=================================================
ynh_script_progression --message="Setting up LDAP plugin..." --weight=3
wget -O qa-ldap-login.zip https://github.com/zakkak/qa-ldap-login/archive/$ldap_login_commit.zip 2>&1
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
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="$install_dir/qa-include/pages/login.php"
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..."
ynh_add_config --template="../conf/qa-config.php" --destination="$install_dir/qa-config.php"
chmod 400 "$install_dir/qa-config.php"
chown $app:$app "$install_dir/qa-config.php"
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$install_dir/qa-config.php"
#=================================================
# 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..." --weight=4
# Installation with curl
ynh_script_progression --message="Finalizing installation..." --weight=4
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"\
`myynh_urlencode "option_site_title=$q2a_name"`\
`myynh_urlencode "option_site_url=https://$domain$path"`\
"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="__EMAIL__" --replace_string="$email" --target_file="../conf/ldap.sql"
ynh_mysql_connect_as --database="$db_name" --user="$db_user" --password="$db_pwd" < ../conf/ldap.sql
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
chown -R $app: $install_dir
chmod o-rwx $install_dir
chown $app:www-data $install_dir
# Remove database initialization file
ynh_secure_remove --file="$install_dir/qa-include/qa-install.php"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last