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

179 lines
5.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
#=================================================
2017-03-19 18:31:53 +01:00
ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée.
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
#=================================================
2014-06-17 23:42:54 +02:00
2017-09-05 00:24:01 +02:00
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)
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
2014-06-17 23:42:54 +02:00
2017-03-01 19:37:00 +01:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2014-06-17 23:42:54 +02:00
2016-12-14 16:08:29 +01:00
ynh_app_setting_set $app admin $admin
ynh_app_setting_set $app language $language
ynh_app_setting_set $app domain $domain
2015-11-22 14:37:01 +01:00
2017-03-01 19:37:00 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# CREATE A SQL BDD
#=================================================
2017-06-13 17:11:10 +02:00
db_name=$(ynh_sanitize_dbid $app)
2017-03-01 19:37:00 +01:00
ynh_app_setting_set $app db_name $db_name
2017-06-13 17:11:10 +02:00
ynh_mysql_setup_db $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
#=================================================
2015-11-22 14:37:01 +01:00
2016-12-14 16:08:29 +01:00
ynh_app_setting_set $app final_path $final_path
2017-06-13 17:11:10 +02:00
ynh_setup_source "$final_path" # Télécharge la source, décompresse et copie dans $final_path
2015-11-22 14:37:01 +01:00
2017-03-01 19:37:00 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2016-06-15 23:56:35 +02:00
2018-01-04 19:29:28 +01:00
if [ "$path_url" != "/" ]
then
ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf"
fi
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
#=================================================
2017-03-19 18:31:53 +01:00
ynh_system_user_create $app # Créer un utilisateur système dédié à l'app
2017-03-01 19:37:00 +01:00
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
2017-09-05 00:24:01 +02:00
ynh_add_fpm_config # Créer le fichier de configuration du pool php-fpm et le configure.
2014-06-17 23:42:54 +02:00
2017-03-01 19:37:00 +01:00
#=================================================
# SPECIFIC SETUP
#=================================================
# SETTING UP WITH CURL
#=================================================
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
# Rend la page d'install publique pour curl
2016-12-14 16:08:29 +01:00
ynh_app_setting_set $app unprotected_uris "/" #L'usage de unprotected_uris a la place de skipped_uris permet de passer le header d'auth http
2017-09-05 00:24:01 +02:00
yunohost app ssowatconf
# Reload Nginx
2017-09-05 00:24:01 +02:00
systemctl reload nginx
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
#=================================================
2015-11-22 14:37:01 +01:00
2017-06-13 17:11:10 +02:00
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
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
#=================================================
# Les fichiers appartiennent à root
2017-09-05 00:24:01 +02:00
chown -R root: $final_path
2017-03-01 19:37:00 +01:00
# $app doit avoir les droits d'écriture dans plugins, cache et 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
#=================================================
ynh_add_fail2ban_config "/var/log/nginx/${domain}-error.log" "PHP message: Leed: wrong login for .* client: <HOST>" 5
2017-03-01 19:37:00 +01:00
#=================================================
# SETUP SSOWAT
#=================================================
# Make app private if necessary
2017-03-01 19:37:00 +01:00
ynh_app_setting_set $app is_public "$is_public"
if [ $is_public -eq 0 ];
then
# Retire l'autorisation d'accès de la page d'install.
2016-12-14 16:08:29 +01:00
ynh_app_setting_delete $app unprotected_uris
# Rend la page d'actualisation accessible pour le script cron.
2017-03-10 22:11:21 +01:00
ynh_app_setting_set $app skipped_uris "/action.php"
fi
2017-03-01 19:37:00 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2017-09-05 00:24:01 +02:00
systemctl reload nginx
2017-12-16 23:21:37 +01:00
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
2017-12-21 20:44:44 +01:00
ynh_print_OFF
2017-12-16 23:21:37 +01:00
message="Please take note of your password for this application: '$user_pwd'.
If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/leed_ynh"
ynh_send_readme_to_admin "$message" "$admin"
2017-12-21 20:44:44 +01:00
ynh_print_ON