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-01-30 19:26:05 +01:00

208 lines
7.5 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
#=================================================
ynh_script_progression --message="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="Check if the app can be installed" --weight=2
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Register (book) web path
ynh_webpath_register $app $domain $path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Store settings from manifest" --weight=2
ynh_app_setting_set $app admin $admin
ynh_app_setting_set $app language $language
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app overwrite_nginx "1"
ynh_app_setting_set $app overwrite_phpfpm "1"
ynh_app_setting_set $app admin_mail_html "1"
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_script_progression --message="Create a mysql database"
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
ynh_mysql_setup_db $db_name $db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Download, check and unpack source" --weight=3
ynh_app_setting_set $app final_path $final_path
# Download, check integrity and uncompress the source from app.src
ynh_setup_source "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configure nginx" --weight=2
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Create a dedicated user" --weight=2
# Create a dedicated system user
ynh_system_user_create $app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Configure php-fpm" --weight=2
# Create a dedicated php-fpm config
ynh_add_fpm_config
#=================================================
# SPECIFIC SETUP
#=================================================
# SETTING UP WITH CURL
#=================================================
ynh_script_progression --message="Install 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 unprotected_uris "/"
# Regen SSOwat configuration
yunohost app ssowatconf
# Reload Nginx
ynh_systemd_action --action=reload --service_name=nginx
# 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="Setup a cron file"
ynh_replace_string "__ADMIN__" "$admin" ../conf/cron_leed
ynh_replace_string "__DOMAIN__" "$domain" ../conf/cron_leed
ynh_replace_string "__PATH__" "$path_url" ../conf/cron_leed
ynh_replace_string "__CODESYNC__" "$code_sync" ../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="Configure 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="Setup SSOwat" --weight=2
# Make app private if necessary
ynh_app_setting_set $app is_public "$is_public"
if [ $is_public -eq 0 ];
then
# Remove the public access
ynh_app_setting_delete $app unprotected_uris
# Set the action.php script public for the cron task
ynh_app_setting_set $app skipped_uris "/action.php"
fi
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reload nginx" --weight=3
ynh_systemd_action --action=reload --service_name=nginx
#=================================================
# 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 completed" --last