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

205 lines
7.9 KiB
Text
Raw Normal View History

2014-06-17 23:42:54 +02:00
#!/bin/bash
2017-03-01 19:37:00 +01:00
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2016-06-15 23:56:35 +02:00
2017-03-19 23:03:07 +01:00
source _common.sh
2017-03-01 19:37:00 +01:00
source /usr/share/yunohost/helpers
#=================================================
# MANAGE FAILURE OF THE SCRIPT
#=================================================
2019-01-19 12:13:45 +01:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2017-03-01 19:37:00 +01:00
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2016-06-15 23:56:35 +02:00
2016-11-08 13:32:06 +01:00
domain=$YNH_APP_ARG_DOMAIN
2017-03-01 19:37:00 +01:00
path_url=$YNH_APP_ARG_PATH
2016-11-08 13:32:06 +01:00
admin=$YNH_APP_ARG_ADMIN
2017-12-21 20:44:44 +01:00
ynh_print_OFF; user_pwd=$YNH_APP_ARG_PASSWORD; ynh_print_ON
2016-11-08 13:32:06 +01:00
language=$YNH_APP_ARG_LANGUAGE
is_public=$YNH_APP_ARG_IS_PUBLIC
app=$YNH_APP_INSTANCE_NAME
2017-03-01 19:37:00 +01:00
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
#=================================================
2019-03-12 20:09:45 +01:00
ynh_script_progression --message="Validating installation parameters..." --weight=2
2014-06-17 23:42:54 +02:00
2017-09-05 00:24:01 +02:00
final_path=/var/www/$app
2019-05-20 23:09:08 +02:00
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2017-09-05 00:24:01 +02:00
# Register (book) web path
2019-05-20 23:09:08 +02:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2014-06-17 23:42:54 +02:00
2017-03-01 19:37:00 +01:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2019-03-12 20:09:45 +01:00
ynh_script_progression --message="Storing installation settings..." --weight=2
2014-06-17 23:42:54 +02:00
2019-05-20 23:09:08 +02:00
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
2019-01-30 19:26:05 +01:00
2019-05-20 23:09:08 +02:00
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
2015-11-22 14:37:01 +01:00
2017-03-01 19:37:00 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
2019-01-19 12:13:45 +01:00
# CREATE A MYSQL DATABASE
2017-03-01 19:37:00 +01:00
#=================================================
2019-03-12 20:09:45 +01:00
ynh_script_progression --message="Creating a MySQL database..."
2017-03-01 19:37:00 +01:00
2019-05-20 23:09:08 +02:00
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
2015-11-22 14:37:01 +01:00
2017-03-01 19:37:00 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2019-03-12 20:09:45 +01:00
ynh_script_progression --message="Setting up source files..." --weight=3
2015-11-22 14:37:01 +01:00
2019-05-20 23:09:08 +02:00
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"
2015-11-22 14:37:01 +01:00
2017-03-01 19:37:00 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-11-25 20:55:09 +01:00
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
2016-06-15 23:56:35 +02:00
2020-11-25 20:55:09 +01:00
# Create a dedicated NGINX config
2017-09-05 00:24:01 +02:00
ynh_add_nginx_config
2015-11-22 14:37:01 +01:00
2017-03-01 19:37:00 +01:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2019-03-12 20:09:45 +01:00
ynh_script_progression --message="Configuring system user..." --weight=2
2017-03-01 19:37:00 +01:00
2019-01-19 12:13:45 +01:00
# Create a dedicated system user
2019-05-20 23:09:08 +02:00
ynh_system_user_create --username=$app
2017-03-01 19:37:00 +01:00
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
2020-11-25 20:55:09 +01:00
ynh_script_progression --message="Configuring PHP-FPM..." --weight=2
2017-03-01 19:37:00 +01:00
2020-11-25 20:55:09 +01:00
# Create a dedicated PHP-FPM config
2019-06-02 13:47:14 +02:00
ynh_add_fpm_config --usage=low --footprint=low
2020-11-25 20:55:09 +01:00
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
2014-06-17 23:42:54 +02:00
2017-03-01 19:37:00 +01:00
#=================================================
# SPECIFIC SETUP
#=================================================
# SETTING UP WITH CURL
#=================================================
2020-11-25 20:55:09 +01:00
ynh_script_progression --message="Installing Leed with cURL..." --weight=5
2014-06-18 00:27:40 +02:00
2014-08-21 23:34:29 +02:00
# Set right permissions for curl install
2017-09-05 00:24:01 +02:00
chown -R $app: $final_path
2014-08-21 23:34:29 +02:00
2019-01-19 12:13:45 +01:00
# Set the app as temporarily public for curl call
2019-05-20 23:09:08 +02:00
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
2019-01-19 12:13:45 +01:00
# Regen SSOwat configuration
2017-09-05 00:24:01 +02:00
yunohost app ssowatconf
# Reload Nginx
2019-05-20 23:09:08 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2014-06-17 23:42:54 +02:00
# Leed installation via curl
2017-12-21 20:44:44 +01:00
ynh_print_OFF
2017-06-13 17:11:10 +02:00
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"
2017-12-21 20:44:44 +01:00
ynh_print_ON
2017-03-01 19:37:00 +01:00
#=================================================
# RETRIEVE SYNCHRONISATION CODE
#=================================================
2015-11-22 14:37:01 +01:00
2017-03-01 19:37:00 +01:00
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)
2017-03-01 19:37:00 +01:00
#=================================================
# SETUP CRON FILE FOR SYNCHRONISATION
#=================================================
2019-03-12 20:09:45 +01:00
ynh_script_progression --message="Setting up a cron file..."
2015-11-22 14:37:01 +01:00
2019-05-20 23:09:08 +02:00
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
2017-09-05 00:24:01 +02:00
cp ../conf/cron_leed /etc/cron.d/$app
2017-03-01 19:37:00 +01:00
#=================================================
# GENERIC FINALISATION
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
2019-01-19 12:13:45 +01:00
# Set permissions to app files
2017-09-05 00:24:01 +02:00
chown -R root: $final_path
2019-01-19 12:13:45 +01:00
# $app need write permissions in plugins, cache and updates
2017-09-05 00:24:01 +02:00
mkdir $final_path/cache
chown -R $app $final_path/cache $final_path/plugins $final_path/updates
2017-03-01 19:37:00 +01:00
2017-12-11 20:37:45 +01:00
#=================================================
# SETUP FAIL2BAN
#=================================================
2020-11-25 20:55:09 +01:00
ynh_script_progression --message="Configuring Fail2Ban..." --weight=9
2017-12-11 20:37:45 +01:00
2019-01-19 12:13:45 +01:00
# Create a dedicated fail2ban config
2019-01-19 12:00:42 +01:00
ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="PHP message: Leed: wrong login for .* client: <HOST>" --max_retry=5
2017-12-11 20:37:45 +01:00
2017-03-01 19:37:00 +01:00
#=================================================
# SETUP SSOWAT
#=================================================
2019-03-12 20:09:45 +01:00
ynh_script_progression --message="Configuring SSOwat..." --weight=2
2017-03-01 19:37:00 +01:00
# Make app private if necessary
2019-05-20 23:09:08 +02:00
ynh_app_setting_set --app=$app --key=is_public --value="$is_public"
2017-03-01 19:37:00 +01:00
if [ $is_public -eq 0 ];
then
2019-01-19 12:13:45 +01:00
# Remove the public access
2019-05-20 23:09:08 +02:00
ynh_app_setting_delete --app=$app --key=unprotected_uris
2019-01-19 12:13:45 +01:00
# Set the action.php script public for the cron task
2019-05-20 23:09:08 +02:00
ynh_app_setting_set --app=$app --key=skipped_uris --value="/action.php"
fi
2017-03-01 19:37:00 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2020-11-25 20:55:09 +01:00
ynh_script_progression --message="Reloading NGINX web server..." --weight=3
2017-03-01 19:37:00 +01:00
2019-05-20 23:09:08 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2017-12-16 23:21:37 +01:00
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
2019-01-21 13:09:35 +01:00
# 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"
2017-12-21 20:44:44 +01:00
ynh_print_OFF
2019-01-30 19:26:05 +01:00
echo "Please take note of your password for this application: '$user_pwd'.
2017-12-16 23:21:37 +01:00
2019-01-30 19:26:05 +01:00
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__.
2019-01-21 13:09:35 +01:00
2019-01-30 19:26:05 +01:00
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
2017-12-16 23:21:37 +01:00
2019-05-20 23:09:08 +02:00
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="$admin" --type=install
2017-12-21 20:44:44 +01:00
ynh_print_ON
2019-01-30 16:15:24 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2019-03-12 20:09:45 +01:00
ynh_script_progression --message="Installation of $app completed" --last