#!/bin/bash set -eu source _common.sh source /usr/share/yunohost/helpers # manage script failure ynh_abort_if_errors # retrieve arguments app=$YNH_APP_INSTANCE_NAME domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH is_public=$YNH_APP_ARG_IS_PUBLIC admin=$YNH_APP_ARG_ADMIN password=$YNH_APP_ARG_PASSWORD backup_core_only=$YNH_APP_ARG_BACKUP_CORE_ONLY # definie useful vars final_path="/var/www/$app" data_path="/home/yunohost.app/$app" # check domain/path availability path_url=$(ynh_normalize_url_path "$path_url") ynh_webpath_available "$domain" "$path_url" ynh_webpath_register "$app" "$domain" "$path_url" myynh_check_path "$final_path" # check that admin user is an existing account ynh_user_exists "$admin" # add required packages ynh_install_app_dependencies "$PKG_DEPENDENCIES" # save app settings ynh_app_setting_set "$app" domain "$domain" ynh_app_setting_set "$app" path "$path_url" ynh_app_setting_set "$app" is_public $is_public ynh_app_setting_set "$app" admin_user "$admin" ynh_app_setting_set "$app" backup_core_only $backup_core_only # create a dedicated system user ynh_system_user_create "$app" # download & unpack bozon TMPDIR=$(mktemp -d) ynh_setup_source "$TMPDIR" # clean & copy files needed to final folder myynh_clean_source mv "$TMPDIR" "$final_path" # create private & data folders myynh_create_dir "$final_path/private" myynh_create_dir "$data_path/uploads" myynh_create_dir "$data_path/thumbs" ln -s "$data_path/uploads" "$final_path/uploads" ln -s "$data_path/thumbs" "$final_path/thumbs" # set permissions myynh_set_permissions # configure nginx settings if [ "$path_url" != "/" ]; then ynh_replace_string "^#sub_path_only" "" "../conf/nginx.conf" fi ynh_add_nginx_config # copy and set php-fpm configuration ynh_add_fpm_config # set temporary public access for curl call ynh_app_setting_set "$app" unprotected_uris "/" yunohost app ssowatconf # fill the superadmin creation form (helper ynh_local_curl doesn't work due to --data vs --data-urlencode ?) admin_url="/index.php?p=login" myynh_local_curl $admin_url sleep 1 myynh_local_curl $admin_url "creation=1" "login=$admin" "pass=$password" "confirm=$password" # if app is private, remove url to SSOWat conf from skipped_uris 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_url" == "/" ] || echo "$path_url" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g') regexList="${domainluaregex}${pathluaregex}/index%.php$","${domainluaregex}${pathluaregex}/index%.php%?p=.*$" ynh_app_setting_set "$app" protected_regex "$regexList" fi