2016-06-13 22:03:33 +02:00
|
|
|
#!/bin/bash
|
2020-06-15 01:58:37 +02:00
|
|
|
|
2020-06-03 23:41:51 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2016-06-13 22:03:33 +02:00
|
|
|
|
2020-06-15 01:58:37 +02:00
|
|
|
source _common.sh
|
2020-06-03 23:41:51 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
2016-06-13 22:03:33 +02:00
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2020-06-03 23:41:51 +02:00
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2016-06-13 22:03:33 +02:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
|
2020-06-15 01:58:37 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2020-06-03 23:41:51 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
2020-06-04 05:36:19 +02:00
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
2020-06-03 23:41:51 +02:00
|
|
|
|
|
|
|
final_path=/var/www/$app
|
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
|
|
|
|
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2020-06-04 06:27:02 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
2016-06-13 22:03:33 +02:00
|
|
|
|
2020-06-03 23:41:51 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
2021-03-28 18:22:10 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
|
2016-06-13 22:03:33 +02:00
|
|
|
|
2020-06-03 23:41:51 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2020-06-04 05:36:19 +02:00
|
|
|
ynh_script_progression --message="Setting up source files..."
|
2016-06-13 22:03:33 +02:00
|
|
|
|
2020-06-03 23:41:51 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2020-06-15 01:58:37 +02:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2020-06-03 23:41:51 +02:00
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2021-03-28 18:43:58 +02:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..."
|
2020-06-03 23:41:51 +02:00
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
if [ "$path_url" != "/" ]
|
|
|
|
then
|
|
|
|
ynh_replace_string "^#sub_path_only" "" "/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
fi
|
2016-06-13 22:03:33 +02:00
|
|
|
|
2020-06-15 01:58:37 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Securing files and directories..."
|
|
|
|
|
|
|
|
# Set permissions to app files
|
|
|
|
chown -R www-data: $final_path
|
|
|
|
|
2020-06-03 23:41:51 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2021-03-16 21:25:15 +01:00
|
|
|
ynh_script_progression --message="Configuring permissions..."
|
2020-06-03 23:41:51 +02:00
|
|
|
|
|
|
|
# If app is public, add url to SSOWat conf as skipped_uris and read-only mode
|
2020-06-15 01:58:37 +02:00
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
2016-06-13 22:03:33 +02:00
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
2021-03-16 21:25:15 +01:00
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
2020-06-04 05:36:19 +02:00
|
|
|
# activate read-only
|
2020-06-03 23:41:51 +02:00
|
|
|
ynh_replace_string --match_string='"readonly": false,' --replace_string='"readonly": true,' --target_file="$final_path/config.js"
|
2016-06-13 22:03:33 +02:00
|
|
|
fi
|
|
|
|
|
2020-06-03 23:41:51 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2021-03-28 18:43:58 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
2020-06-03 23:41:51 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2020-06-15 01:58:37 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed"
|