2017-01-28 22:05:00 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-06-26 17:14:28 +02:00
|
|
|
#=================================================
|
2018-03-24 01:16:50 +01:00
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
2017-06-26 17:14:28 +02:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
2017-01-28 22:05:00 +01:00
|
|
|
|
2018-03-24 01:16:50 +01:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2017-06-26 17:14:28 +02:00
|
|
|
#=================================================
|
2017-01-28 22:05:00 +01:00
|
|
|
# Retrieve arguments
|
2017-06-26 17:14:28 +02:00
|
|
|
#=================================================
|
|
|
|
|
2020-04-29 02:16:04 +02:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2020-04-29 02:25:10 +02:00
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2020-04-29 02:44:02 +02:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2020-04-29 02:16:04 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2017-01-28 22:05:00 +01:00
|
|
|
|
2017-06-26 17:14:28 +02:00
|
|
|
#=================================================
|
2018-03-24 01:16:50 +01:00
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
2017-06-26 17:14:28 +02:00
|
|
|
#=================================================
|
2020-04-04 03:34:57 +02:00
|
|
|
ynh_script_progression --message="Validating installation parameters..." --time --weight=1
|
2017-06-26 17:14:28 +02:00
|
|
|
|
2018-03-24 01:16:50 +01:00
|
|
|
final_path=/var/www/$app
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
2017-02-11 20:26:05 +01:00
|
|
|
|
2018-03-24 01:16:50 +01:00
|
|
|
# Normalize the url path syntax
|
|
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
2017-02-12 11:08:59 +01:00
|
|
|
|
2018-03-24 01:16:50 +01:00
|
|
|
# Check web path availability
|
|
|
|
ynh_webpath_available $domain $path_url
|
|
|
|
# Register (book) web path
|
2020-04-04 03:34:57 +02:00
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
2017-02-11 19:50:47 +01:00
|
|
|
|
2017-06-26 17:14:28 +02:00
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2020-04-04 03:34:57 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..." --time --weight=1
|
2017-06-26 17:14:28 +02:00
|
|
|
|
2020-04-04 03:34:57 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
2017-06-26 17:14:28 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-01-28 23:11:24 +01:00
|
|
|
# Install dependency to convert tracks to a readable format for the browser
|
2017-06-26 17:14:28 +02:00
|
|
|
#=================================================
|
2020-04-04 03:34:57 +02:00
|
|
|
ynh_script_progression --message="Installing dependencies..." --time --weight=1
|
2020-03-31 17:43:53 +02:00
|
|
|
|
2020-06-15 12:06:02 +02:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
2017-01-29 16:06:11 +01:00
|
|
|
|
2017-06-26 17:14:28 +02:00
|
|
|
#=================================================
|
2018-03-24 01:16:50 +01:00
|
|
|
# CREATE DEDICATED USER
|
2017-06-26 17:14:28 +02:00
|
|
|
#=================================================
|
2020-04-04 03:34:57 +02:00
|
|
|
ynh_script_progression --message="Configuring system user..." --time --weight=1
|
2018-03-24 01:16:50 +01:00
|
|
|
# Create a system user
|
2020-04-04 03:34:57 +02:00
|
|
|
ynh_system_user_create --username=$app
|
2017-01-28 22:05:00 +01:00
|
|
|
|
2017-06-26 17:14:28 +02:00
|
|
|
#=================================================
|
2018-03-24 01:16:50 +01:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2017-06-26 17:14:28 +02:00
|
|
|
#=================================================
|
2020-04-04 03:34:57 +02:00
|
|
|
ynh_script_progression --message="Setting up source files..." --time --weight=1
|
2017-06-26 17:14:28 +02:00
|
|
|
|
2020-04-04 03:34:57 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2018-03-24 01:16:50 +01:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2020-04-04 03:34:57 +02:00
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
2018-03-24 01:16:50 +01:00
|
|
|
|
2017-01-28 22:05:00 +01:00
|
|
|
|
2017-06-26 17:14:28 +02:00
|
|
|
#=================================================
|
2018-03-24 01:16:50 +01:00
|
|
|
# NGINX CONFIGURATION
|
2017-06-26 17:14:28 +02:00
|
|
|
#=================================================
|
2020-04-04 03:34:57 +02:00
|
|
|
ynh_script_progression --message="Configuring nginx web server..." --time --weight=1
|
2018-03-24 01:16:50 +01:00
|
|
|
# Create a dedicated nginx config
|
2020-04-02 16:34:46 +02:00
|
|
|
ynh_add_nginx_config
|
2017-01-28 22:05:00 +01:00
|
|
|
|
2018-03-24 01:25:15 +01:00
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2020-04-04 03:34:57 +02:00
|
|
|
ynh_script_progression --message="Configuring php-fpm..." --time --weight=1
|
2018-03-24 01:25:15 +01:00
|
|
|
|
|
|
|
# Create a dedicated php-fpm config
|
2020-04-02 16:34:46 +02:00
|
|
|
ynh_add_fpm_config
|
2018-03-24 01:25:15 +01:00
|
|
|
|
2017-06-26 17:14:28 +02:00
|
|
|
#=================================================
|
2020-04-29 01:16:00 +02:00
|
|
|
# Files owned by user app
|
2017-06-26 17:14:28 +02:00
|
|
|
#=================================================
|
2020-04-04 03:34:57 +02:00
|
|
|
|
2020-04-29 01:16:00 +02:00
|
|
|
chown $app:$app $final_path -R
|
|
|
|
chmod 755 $final_path -R
|
|
|
|
|
|
|
|
# Remove the public access
|
|
|
|
ynh_app_setting_delete --app=$app --key=skipped_uris
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring permissions..." --time --weight=1
|
|
|
|
|
2018-03-24 01:16:50 +01:00
|
|
|
# Make app public if necessary
|
|
|
|
if [ $is_public -eq 1 ]
|
2017-01-28 22:05:00 +01:00
|
|
|
then
|
2020-04-29 01:16:00 +02:00
|
|
|
# Everyone can access the app.
|
|
|
|
# The "main" permission is automatically created before the install script.
|
|
|
|
ynh_permission_update --permission "main" --add "visitors"
|
2017-01-28 22:05:00 +01:00
|
|
|
fi
|
2020-04-29 01:16:00 +02:00
|
|
|
# Only the users can access to the panel of the app
|
|
|
|
# ynh_permission_update --permission="main" --add "all_users"
|
2020-04-04 03:34:57 +02:00
|
|
|
|
2020-04-09 13:05:20 +02:00
|
|
|
#=================================================
|
2020-04-10 17:07:35 +02:00
|
|
|
# MODIFY A CONFIG FILE
|
2020-04-09 13:05:20 +02:00
|
|
|
#=================================================
|
2020-04-10 17:45:02 +02:00
|
|
|
# copy config.dist.php creating config.local.php
|
2020-04-09 14:54:14 +02:00
|
|
|
cp -a $final_path/config.dist.php $final_path/config.local.php
|
2020-04-10 17:45:02 +02:00
|
|
|
# create a key for the secret key CSFR;
|
|
|
|
key=$(ynh_string_random --length=50)
|
|
|
|
# edit config.local.php
|
2020-04-11 16:33:40 +02:00
|
|
|
ynh_replace_string --match_string="const SECRET_KEY = '3xUhIgGwuovRKOjVsVPQ5yUMfXUSIOX2GKzcebsz5OINrYC50r';" --replace_string="const SECRET_KEY = '$key';" --target_file="$final_path/config.local.php"
|
2020-04-10 17:45:02 +02:00
|
|
|
if [ "$path_url" == "/" ]; then
|
2020-04-09 16:00:23 +02:00
|
|
|
ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url';" --target_file="$final_path/config.local.php"
|
|
|
|
else
|
|
|
|
ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url/';" --target_file="$final_path/config.local.php"
|
|
|
|
fi
|
|
|
|
|
2020-04-10 17:07:35 +02:00
|
|
|
#=================================================
|
2020-04-29 01:16:00 +02:00
|
|
|
# RELOAD NGINX
|
2020-04-10 17:07:35 +02:00
|
|
|
#=================================================
|
2020-04-29 01:16:00 +02:00
|
|
|
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
|
2020-04-10 17:07:35 +02:00
|
|
|
|
2020-04-29 01:16:00 +02:00
|
|
|
systemctl reload nginx
|
2020-04-10 17:07:35 +02:00
|
|
|
|
2020-04-04 03:34:57 +02:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2017-06-26 17:14:28 +02:00
|
|
|
|
2020-04-04 03:34:57 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --time --last
|