#!/bin/bash # causes the shell to exit if any subcommand or pipeline returns a non-zero status set -e # Source YNH helpers . /usr/share/yunohost/helpers # This is a multi-instance app, meaning it can be installed several times independently # The id of the app as stated in the manifest is available as $YNH_APP_ID # The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) # The app instance name is available as $YNH_APP_INSTANCE_NAME # - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample # - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 # - ynhexample__{N} for the subsequent installations, with N=3,4, ... # The app instance name is probably what you are interested the most, since this is # guaranteed to be unique. This is a good unique identifier to define installation path, # db names, ... app=$YNH_APP_INSTANCE_NAME # Retrieve arguments domain=$(ynh_app_setting_get "$app" domain) path=$(ynh_app_setting_get "$app" path) is_public=$(ynh_app_setting_get "$app" is_public) redirect_type=$(ynh_app_setting_get "$app" redirect_type) redirect_path=$(ynh_app_setting_get "$app" redirect_path) # Remove trailing slash to path path=${path%/} # Check domain/path availability sudo yunohost app checkurl $domain$path -a $app \ || die "The path ${domain}${path} is not available for app installation." # Validate redirect path url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]' [[ ! $redirect_path =~ $url_regex ]] && ynh_die \ "Invalid destination: $redirect_path" 1 # Check configuration files NGINX_CONF="/etc/nginx/conf.d/${domain}.d/${app}.conf" [[ -f $NGINX_CONF ]] && die \ "The NGINX configuration already exists at '${NGINX_CONF}'. You should safely delete it before restoring this app." # Restore configuration files sudo cp -a ./conf/nginx.conf "$NGINX_CONF" # Make app public if necessary if [[ "$is_public" -ne 0 ]]; then sudo yunohost app setting $app unprotected_uris -v "/" fi # Reload Nginx and regenerate SSOwat conf sudo service nginx reload sudo yunohost app ssowatconf