2016-06-13 22:03:33 +02:00
|
|
|
|
#!/bin/bash
|
2020-06-03 23:41:51 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# GENERIC START
|
|
|
|
|
#=================================================
|
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
|
#=================================================
|
2016-06-13 22:03:33 +02:00
|
|
|
|
|
2020-06-03 23:41:51 +02:00
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
|
|
|
|
### Remove this function if there's nothing to clean before calling the remove script.
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
# Retrieve arguments
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
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-03 23:41:51 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_script_progression --message="Validating installation parameters..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
final_path=/var/www/$app
|
|
|
|
|
test ! -e "$final_path" || ynh_die --message="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=$app --domain=$domain --path_url=$path_url
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_script_progression --message="Storing installation settings..." --time --weight=1
|
2016-06-13 22:03:33 +02:00
|
|
|
|
|
|
|
|
|
# Save app settings
|
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
|
|
|
|
|
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
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_script_progression --message="Setting up source files..." --time --weight=1
|
2016-06-13 22:03:33 +02:00
|
|
|
|
|
|
|
|
|
# Retrieve sources and install them
|
2020-06-03 23:41:51 +02:00
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2019-07-30 23:07:10 +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"
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# Permissions files
|
|
|
|
|
#=================================================
|
|
|
|
|
|
2020-06-03 23:46:53 +02:00
|
|
|
|
chown -R www-data: $final_path
|
2016-06-13 22:03:33 +02:00
|
|
|
|
|
2020-06-03 23:41:51 +02:00
|
|
|
|
# Remove the public access
|
|
|
|
|
ynh_app_setting_delete --app=$app --key=skipped_uris
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_script_progression --message="Configuring nginx web server..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
### `ynh_add_nginx_config` will use the file conf/nginx.conf
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
2020-06-03 23:57:07 +02:00
|
|
|
|
|
2020-06-03 23:41:51 +02:00
|
|
|
|
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-03 23:41:51 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# SETUP SSOWAT
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_script_progression --message="Configuring SSOwat..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# If app is public, add url to SSOWat conf as skipped_uris and read-only mode
|
2016-06-13 22:03:33 +02:00
|
|
|
|
if [[ $is_public -eq 1 ]]; then
|
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
2020-06-03 23:41:51 +02:00
|
|
|
|
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
|
2020-06-02 18:14:52 +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
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
|
|
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# END OF SCRIPT
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --time --last
|