#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= #REMOVEME? ynh_clean_setup () { true } # Exit if an error occurs during the execution of the script #REMOVEME? ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= #REMOVEME? domain=$YNH_APP_ARG_DOMAIN #REMOVEME? path=$YNH_APP_ARG_PATH #REMOVEME? is_public=$YNH_APP_ARG_IS_PUBLIC #REMOVEME? admin=$YNH_APP_ARG_ADMIN #REMOVEME? password=$YNH_APP_ARG_PASSWORD #REMOVEME? app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= #REMOVEME? ynh_script_progression --message="Validating installation parameters..." --weight=1 #REMOVEME? install_dir=/var/www/$app #REMOVEME? data_dir="/home/yunohost.app/$app" path=$(ynh_normalize_url_path --path="$path") #REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder" # Register (book) web path #REMOVEME? ynh_webpath_register --app=$app --domain=$domain --path=$path ## check that admin user is an existing account ynh_user_exists --username="$admin" #================================================= # STORE SETTINGS FROM MANIFEST #================================================= #REMOVEME? ynh_script_progression --message="Storing installation settings..." --weight=1 #REMOVEME? ynh_app_setting_set --app=$app --key=domain --value=$domain #REMOVEME? ynh_app_setting_set --app=$app --key=path --value=$path #REMOVEME? ynh_app_setting_set --app=$app --key=admin_user --value=$admin #REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value="$install_dir" #REMOVEME? ynh_app_setting_set --app=$app --key=data_dir --value="$data_dir" #================================================= # STANDARD MODIFICATIONS #================================================= # INSTALL DEPENDENCIES #================================================= #REMOVEME? ynh_script_progression --message="Installing dependencies..." --weight=3 #REMOVEME? ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER #================================================= #REMOVEME? ynh_script_progression --message="Configuring system user..." --weight=1 # Create a system user #REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=3 ## download source tmpdir=$(mktemp -d) ynh_setup_source --dest_dir="$tmpdir" ## clean & copy files needed to final folder myynh_clean_source mv "$tmpdir" "$install_dir" #================================================= # PHP-FPM CONFIGURATION #================================================= ynh_script_progression --message="Configuring PHP-FPM..." --weight=1 # Create a dedicated PHP-FPM config ynh_add_fpm_config #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=1 if [ "$path" != "/" ]; then ynh_replace_string --match_string="^#sub_path_only" --replace_string="" --target_file="../conf/nginx.conf" fi ynh_add_nginx_config #================================================= # SPECIFIC SETUP #================================================= # CREATE DATA DIRECTORY #================================================= ynh_script_progression --message="Creating a data directory..." --weight=1 #REMOVEME? data_dir=/home/yunohost.app/$app #REMOVEME? ynh_app_setting_set --app=$app --key=data_dir --value=$data_dir mkdir -p $data_dir #================================================= # ADD A CONFIGURATION #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 ## create private & data folders myynh_create_dir "$install_dir/private" myynh_create_dir "$data_dir/uploads" myynh_create_dir "$data_dir/thumbs" ln -s "$data_dir/uploads" "$install_dir/uploads" ln -s "$data_dir/thumbs" "$install_dir/thumbs" ## set permissions myynh_set_permissions #================================================= # SETUP APPLICATION WITH CURL #================================================= ynh_script_progression --message="Configuring admin user in BoZon..." --weight=2 # Set the app as temporarily public for curl call ynh_script_progression --message="Configuring SSOwat..." # Making the app public for curl #REMOVEME? ynh_permission_update --permission="main" --add="visitors" ## fill the superadmin creation form (helper ynh_local_curl doesn't work due to --data vs --data-urlencode ?) admin_url="/index.php?p=login" admin=$(myynh_urlencode $admin) password=$(myynh_urlencode $password) ynh_local_curl $admin_url "creation=1" "login=$admin" "pass=$password" "confirm=$password" #================================================= # GENERIC FINALIZATION #================================================= # SETUP SSOWAT #================================================= ynh_script_progression --message="Configuring SSOwat..." --weight=1 #REMOVEME? if [ $is_public -eq 0 ]; then # escape magic chars in vars (lua magic chars are ().%+-*?[^$ according to https://www.lua.org/pil/20.2.html) domainluaregex=$(echo "$domain" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g') pathluaregex=$([ "$path" == "/" ] || echo "$path" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g') regexList="${domainluaregex}${pathluaregex}/index%.php$","${domainluaregex}${pathluaregex}/index%.php%?p=.*$" ynh_app_setting_set --app="$app" --key=protected_regex --value="$regexList" fi #================================================= # RELOAD NGINX #================================================= #REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1 #REMOVEME? ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last