1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/leed_ynh.git synced 2024-09-03 19:26:32 +02:00
leed_ynh/scripts/install
2019-05-20 23:09:08 +02:00

204 lines
7.9 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE FAILURE OF THE SCRIPT
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
ynh_print_OFF; user_pwd=$YNH_APP_ARG_PASSWORD; ynh_print_ON
language=$YNH_APP_ARG_LANGUAGE
is_public=$YNH_APP_ARG_IS_PUBLIC
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=2
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=2
ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_app_setting_set --app=$app --key=language --value=$language
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=1
ynh_app_setting_set --app=$app --key=overwrite_phpfpm --value=1
ynh_app_setting_set --app=$app --key=admin_mail_html --value=1
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_script_progression --message="Creating a MySQL database..."
db_name=$(ynh_sanitize_dbid --db_name=$app)
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=3
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring nginx web server..." --weight=2
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=2
# Create a dedicated system user
ynh_system_user_create --username=$app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring php-fpm..." --weight=2
# Create a dedicated php-fpm config
ynh_add_fpm_config
#=================================================
# SPECIFIC SETUP
#=================================================
# SETTING UP WITH CURL
#=================================================
ynh_script_progression --message="Installing Leed with Curl..." --weight=5
# Set right permissions for curl install
chown -R $app: $final_path
# Set the app as temporarily public for curl call
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
# Regen SSOwat configuration
yunohost app ssowatconf
# Reload Nginx
ynh_systemd_action --service_name=nginx --action=reload
# Leed installation via curl
ynh_print_OFF
ynh_local_curl "/install.php?installButton" "install_changeLngLeed=$language" "root=$domain$path_url" "mysqlHost=localhost" "mysqlLogin=$db_name" "mysqlMdp=$db_pwd" "mysqlBase=$db_name" "mysqlPrefix=leed_" "login=$admin" "password=$user_pwd"
ynh_print_ON
#=================================================
# RETRIEVE SYNCHRONISATION CODE
#=================================================
code_sync=$(mysql -h localhost -u $db_name -p$db_pwd -s $db_name -e 'SELECT value FROM leed_configuration WHERE `key`="synchronisationCode"' | sed -n 1p)
#=================================================
# SETUP CRON FILE FOR SYNCHRONISATION
#=================================================
ynh_script_progression --message="Setting up a cron file..."
ynh_replace_string --match_string="__ADMIN__" --replace_string="$admin" --target_file=../conf/cron_leed
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file=../conf/cron_leed
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file=../conf/cron_leed
ynh_replace_string --match_string="__CODESYNC__" --replace_string="$code_sync" --target_file=../conf/cron_leed
cp ../conf/cron_leed /etc/cron.d/$app
#=================================================
# GENERIC FINALISATION
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
chown -R root: $final_path
# $app need write permissions in plugins, cache and updates
mkdir $final_path/cache
chown -R $app $final_path/cache $final_path/plugins $final_path/updates
#=================================================
# SETUP FAIL2BAN
#=================================================
ynh_script_progression --message="Configuring fail2ban..." --weight=9
# Create a dedicated fail2ban config
ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="PHP message: Leed: wrong login for .* client: <HOST>" --max_retry=5
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring SSOwat..." --weight=2
# Make app private if necessary
ynh_app_setting_set --app=$app --key=is_public --value="$is_public"
if [ $is_public -eq 0 ];
then
# Remove the public access
ynh_app_setting_delete --app=$app --key=unprotected_uris
# Set the action.php script public for the cron task
ynh_app_setting_set --app=$app --key=skipped_uris --value="/action.php"
fi
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..." --weight=3
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
# Get main domain and buid the url of the admin panel of the app.
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
ynh_print_OFF
echo "Please take note of your password for this application: '$user_pwd'.
You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.
You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__.
If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/leed_ynh__URL_TAG3__." > mail_to_send
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="$admin" --type=install
ynh_print_ON
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last