2014-01-13 13:50:38 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-09-28 18:02:10 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2019-02-13 21:13:59 +01:00
|
|
|
source _common.sh
|
2017-09-28 18:02:10 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
2019-02-13 21:13:59 +01:00
|
|
|
# MANAGE SCRIPT FAILURE
|
2017-09-28 18:02:10 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-02-13 21:13:59 +01:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2017-09-28 18:02:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
2016-05-13 21:34:03 +02:00
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2017-09-28 18:02:10 +02:00
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2016-05-13 21:34:03 +02:00
|
|
|
admin_user=$YNH_APP_ARG_ADMIN_USER
|
2019-05-25 11:33:11 +02:00
|
|
|
ynh_print_OFF
|
2016-05-13 21:34:03 +02:00
|
|
|
upload_password=$YNH_APP_ARG_UPLOAD_PASSWORD
|
2019-05-25 11:33:11 +02:00
|
|
|
ynh_print_ON
|
2016-05-13 21:34:03 +02:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2014-01-13 13:50:38 +01:00
|
|
|
|
2017-09-28 18:02:10 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2014-01-13 13:50:38 +01:00
|
|
|
|
2017-09-28 18:02:10 +02:00
|
|
|
#=================================================
|
2019-02-13 21:13:59 +01:00
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
2017-09-28 18:02:10 +02:00
|
|
|
#=================================================
|
2020-10-15 09:07:23 +02:00
|
|
|
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
2015-01-31 23:01:16 +01:00
|
|
|
|
2017-09-28 18:02:10 +02:00
|
|
|
final_path=/var/www/$app
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
|
|
|
|
|
|
|
# Register (book) web path
|
2019-05-06 14:14:36 +02:00
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
2017-09-28 18:02:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2020-10-15 09:07:23 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..." --weight=1
|
2017-09-28 18:02:10 +02:00
|
|
|
|
2019-05-06 14:14:36 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
|
|
|
ynh_app_setting_set --app=$app --key=admin --value=$admin_user
|
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
|
2017-09-28 18:02:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2019-05-06 14:14:36 +02:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=3
|
2017-09-28 18:02:10 +02:00
|
|
|
|
2019-05-06 14:14:36 +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"
|
2017-09-28 18:02:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2020-10-15 09:07:23 +02:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..."
|
2017-09-28 18:02:10 +02:00
|
|
|
|
2020-11-09 16:04:43 +01:00
|
|
|
# Create a dedicated NGINX config
|
2017-09-28 18:02:10 +02:00
|
|
|
ynh_add_nginx_config
|
2014-01-13 21:36:14 +01:00
|
|
|
|
2017-09-28 18:02:10 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2019-05-06 14:14:36 +02:00
|
|
|
ynh_script_progression --message="Configuring system user..." --weight=2
|
2017-09-28 18:02:10 +02:00
|
|
|
|
|
|
|
# Create a system user
|
2019-05-06 14:14:36 +02:00
|
|
|
ynh_system_user_create --username=$app
|
2017-09-28 18:02:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2020-10-15 09:07:23 +02:00
|
|
|
ynh_script_progression --message="Configuring PHP-FPM..." --weight=2
|
2017-09-28 18:02:10 +02:00
|
|
|
|
2020-10-15 09:07:23 +02:00
|
|
|
# Create a dedicated PHP-FPM config
|
2020-11-09 16:04:43 +01:00
|
|
|
ynh_add_fpm_config
|
2020-10-15 09:07:23 +02:00
|
|
|
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
2017-09-28 18:02:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# SET AND SAVE THE UPLOAD PASSWORD
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
jirafeauconfigfile="$final_path/lib/config.local.php"
|
|
|
|
cp "../conf/config.local.php" "$jirafeauconfigfile"
|
2014-01-13 13:50:38 +01:00
|
|
|
|
2015-07-13 22:28:21 +02:00
|
|
|
# Set and save upload password, allowing an empty one
|
2019-05-25 11:33:11 +02:00
|
|
|
ynh_print_OFF
|
2017-09-28 18:02:10 +02:00
|
|
|
if [ -z "$upload_password" ]
|
|
|
|
then
|
2021-04-11 18:58:39 +02:00
|
|
|
ynh_replace_string --match_string="__UPLOAD_PASSWORD__" --replace_string="" --target_file="$jirafeauconfigfile"
|
2019-05-06 14:14:36 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=upload_password --value=""
|
2015-07-13 22:28:21 +02:00
|
|
|
else
|
2021-04-11 18:58:39 +02:00
|
|
|
ynh_replace_special_string --match_string="__UPLOAD_PASSWORD__" --replace_string="'$upload_password'" --target_file="$jirafeauconfigfile"
|
2019-05-06 14:14:36 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=upload_password --value="$upload_password"
|
2015-07-13 22:28:21 +02:00
|
|
|
fi
|
2019-05-25 11:33:11 +02:00
|
|
|
ynh_print_ON
|
2015-07-13 22:28:21 +02:00
|
|
|
|
2017-09-28 18:02:10 +02:00
|
|
|
#=================================================
|
|
|
|
# CONFIGURE JIRAFEAU
|
|
|
|
#=================================================
|
2020-10-15 09:07:23 +02:00
|
|
|
ynh_script_progression --message="Configuring Jirafeau..." --weight=2
|
2017-09-28 18:02:10 +02:00
|
|
|
|
2016-05-13 21:34:03 +02:00
|
|
|
var_root=/home/yunohost.app/$app
|
2019-02-13 21:13:59 +01:00
|
|
|
|
2021-04-11 18:58:39 +02:00
|
|
|
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$jirafeauconfigfile"
|
2017-09-28 18:02:10 +02:00
|
|
|
if [ "$path_url" = "/" ]
|
|
|
|
then
|
2021-04-11 18:58:39 +02:00
|
|
|
ynh_replace_string --match_string="__PATH__" --replace_string="" --target_file="$jirafeauconfigfile"
|
2015-05-23 15:29:21 +02:00
|
|
|
else
|
2021-04-11 18:58:39 +02:00
|
|
|
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$jirafeauconfigfile"
|
2015-05-23 15:29:21 +02:00
|
|
|
fi
|
2021-04-11 18:58:39 +02:00
|
|
|
ynh_replace_string --match_string="__VAR_ROOT__" --replace_string="$var_root" --target_file="$jirafeauconfigfile"
|
|
|
|
ynh_replace_string --match_string="__ADMIN_USER__" --replace_string="$admin_user" --target_file="$jirafeauconfigfile"
|
2017-09-28 18:02:10 +02:00
|
|
|
|
|
|
|
# Calculate and store the config file checksum into the app settings
|
2019-05-06 14:14:36 +02:00
|
|
|
ynh_store_file_checksum --file="$jirafeauconfigfile"
|
2017-09-28 18:02:10 +02:00
|
|
|
|
|
|
|
# Remove the install.php
|
2019-05-17 10:44:19 +02:00
|
|
|
ynh_secure_remove --file=$final_path/install.php
|
2017-09-28 18:02:10 +02:00
|
|
|
|
2020-03-03 20:23:09 +01:00
|
|
|
#=================================================
|
|
|
|
# SET THE CRON FILE
|
|
|
|
#=================================================
|
2020-10-15 09:07:23 +02:00
|
|
|
ynh_script_progression --message="Configuring the cron file..." --weight=2
|
2020-03-03 20:23:09 +01:00
|
|
|
|
2021-04-11 18:58:39 +02:00
|
|
|
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
|
2020-03-03 20:23:09 +01:00
|
|
|
|
2017-09-28 18:02:10 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALISATION
|
|
|
|
#=================================================
|
|
|
|
# SECURING FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
chown -R root: $final_path
|
|
|
|
|
|
|
|
mkdir -p $var_root/{files,links,async,block}
|
|
|
|
chown -R $app:root $var_root
|
|
|
|
chmod -R 700 $var_root
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2021-02-14 11:27:24 +01:00
|
|
|
ynh_script_progression --message="Configuring permissions..." --weight=2
|
|
|
|
|
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
2017-09-28 18:02:10 +02:00
|
|
|
|
|
|
|
if [ $is_public -eq 0 ]
|
2014-01-13 13:50:38 +01:00
|
|
|
then
|
2017-09-28 18:02:10 +02:00
|
|
|
domain_regex=$(echo "$domain" | sed 's@-@.@g')
|
|
|
|
[ "$path_url" = "/" ] && path_url=""
|
2019-05-06 14:14:36 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/$","$domain_regex$path_url/admin.php.*$"
|
2014-01-13 13:50:38 +01:00
|
|
|
fi
|
|
|
|
|
2017-09-28 18:02:10 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2020-10-15 09:07:23 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
2017-09-28 18:02:10 +02:00
|
|
|
|
2019-05-06 14:14:36 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2019-02-17 20:55:13 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2020-10-15 09:07:23 +02:00
|
|
|
ynh_script_progression --message="Installation of Jirafeau completed" --last
|