1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/redirect_ynh.git synced 2024-09-03 20:16:10 +02:00

Add basic helpers

This commit is contained in:
Jean-Baptiste Holcroft 2018-05-26 10:27:01 +02:00
parent 0518b75125
commit a46bb24470
5 changed files with 153 additions and 26 deletions

View file

@ -1,10 +1,29 @@
#!/bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Source YNH helpers
. /usr/share/yunohost/helpers
# if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
# cp ../settings/scripts/_common.sh ./_common.sh
# chmod a+rx _common.sh
# fi
# source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
# 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

View file

@ -1,10 +1,24 @@
#!/bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -ue
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Source app helpers
. /usr/share/yunohost/helpers
# source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
# 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
@ -32,7 +46,7 @@ location=${path:-/}
# Check domain/path availability
yunohost app checkurl $domain$path -a $app \
|| (echo "Path not available: $domain$path" && exit 1)
|| ynh_die "Path not available: $domain$path"
# Validate redirect path
url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
@ -60,11 +74,21 @@ then
cp ../conf/nginx-proxy.conf /etc/nginx/conf.d/$domain.d/$app.conf
fi
# Make app public if necessary
if [[ "$is_public" -ne 0 ]];
then
yunohost app setting $app unprotected_uris -v "/"
#=================================================
# SETUP SSOWAT
#=================================================
if [[ "$is_public" -eq 0 ]]
then # Remove the public access
ynh_app_setting_delete "$app" skipped_uris
fi
# Make app public if necessary
if [[ "$is_public" -eq 1 ]]
then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set "$app" unprotected_uris "/"
fi
# Reload Nginx and regenerate SSOwat conf
service nginx reload

View file

@ -1,7 +1,17 @@
#!/bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
# 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

View file

@ -1,10 +1,29 @@
#!/bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Source YNH helpers
. /usr/share/yunohost/helpers
# if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
# cp ../settings/scripts/_common.sh ./_common.sh
# chmod a+rx _common.sh
# fi
# source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
# 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
@ -46,10 +65,19 @@ NGINX_CONF="/etc/nginx/conf.d/${domain}.d/${app}.conf"
# Restore configuration files
cp -a ./conf/nginx.conf "$NGINX_CONF"
#=================================================
# SETUP SSOWAT
#=================================================
if [[ "$is_public" -eq 0 ]]
then # Remove the public access
ynh_app_setting_delete "$app" skipped_uris
fi
# Make app public if necessary
if [[ "$is_public" -ne 0 ]];
if [[ "$is_public" -eq 1 ]]
then
yunohost app setting $app unprotected_uris -v "/"
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set "$app" unprotected_uris "/"
fi
# Reload Nginx and regenerate SSOwat conf

View file

@ -1,7 +1,18 @@
#!/bin/bash
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
set -e
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
# 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
@ -25,6 +36,19 @@ 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)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0
is_public=0
fi
# Default value for redirect_type if upgrading from https://github.com/scith/redirect_ynh
if [ -z "$redirect_type" ];
then
@ -32,6 +56,19 @@ then
ynh_app_setting_set $app 'redirect_type' $redirect_type
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# Remove trailing slash to path
path=${path%/}
#force location to be / or /foo
@ -39,7 +76,7 @@ location=${path:-/}
# Check domain/path availability
yunohost app checkurl $domain$path -a $app \
|| (echo "Path not available: $domain$path" && exit 1)
|| ynh_die "Path not available: $domain$path"
# Validate redirect path
url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
@ -62,10 +99,19 @@ then
cp ../conf/nginx-proxy.conf /etc/nginx/conf.d/$domain.d/$app.conf
fi
#=================================================
# SETUP SSOWAT
#=================================================
if [[ "$is_public" -eq 0 ]]
then # Remove the public access
ynh_app_setting_delete "$app" skipped_uris
fi
# Make app public if necessary
if [[ "$is_public" -ne 0 ]];
if [[ "$is_public" -eq 1 ]]
then
yunohost app setting $app unprotected_uris -v "/"
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set "$app" unprotected_uris -v "/"
fi
# Reload Nginx and regenerate SSOwat conf