1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/radicale_ynh.git synced 2024-09-03 20:16:14 +02:00
radicale_ynh/scripts/actions/add_remove_infcloud
2019-01-18 21:12:58 +01:00

171 lines
5.3 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
infcloud=$(ynh_app_setting_get $app infcloud)
final_path=$(ynh_app_setting_get $app final_path)
#=================================================
# CHECK IF AN ACTION HAS TO BE DONE
#=================================================
if [ $infcloud -eq 1 ]
then
ynh_print_info "InfCloud will be removed." >&2
infcloud=0
else
ynh_print_info "InfCloud will be installed." >&2
infcloud=1
fi
#=================================================
# SPECIFIC ACTION
#=================================================
# INSTALL OR REMOVE INFCLOUD
#=================================================
if [ $infcloud -eq 1 ]
then
# Install InfCloud
# Get settings
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
language=$(ynh_app_setting_get $app language)
admin=$(ynh_app_setting_get $app admin)
# Optional parameters from config-panel feature
firstdayofweek=$(ynh_app_setting_get $app firstdayofweek)
activeview=$(ynh_app_setting_get $app activeview)
openformmode=$(ynh_app_setting_get $app openformmode)
startofbusiness=$(ynh_app_setting_get $app startofbusiness)
endofbusiness=$(ynh_app_setting_get $app endofbusiness)
defaulteventduration=$(ynh_app_setting_get $app defaulteventduration)
# Add InfCloud to nginx config
ynh_replace_string "#INFCLOUD#" "" /etc/nginx/conf.d/$domain.d/$app.conf
# Install InfCloud
(YNH_CWD="$YNH_CWD/scripts"; ynh_setup_source "$final_path/infcloud")
# InfCloud configuration
# Set language
case "$language" in
"Czech") language="cs_CZ"
;;
"Danish") language="da_DK"
;;
"German") language="de_DE"
;;
"English/US") language="en_US"
;;
"Spanish") language="es_ES"
;;
"French") language="fr_FR"
;;
"Italian") language="it_IT"
;;
"Japan") language="ja_JP"
;;
"Hungarian") language="hu_HU"
;;
"Dutch") language="nl_NL"
;;
"Slovak") language="sk_SK"
;;
"Turkish") language="tr_TR"
;;
"Russian") language="ru_RU"
;;
"Ukrainian") language="uk_UA"
;;
"Chinese") language="zh_CN"
;;
esac
cp conf/config.js "$final_path/infcloud/"
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/infcloud/config.js"
ynh_replace_string "__PATH__" "${path_url%/}" "$final_path/infcloud/config.js"
ynh_replace_string "__LANG__" "$language" "$final_path/infcloud/config.js"
ynh_replace_string "__ADMIN__" "$admin" "$final_path/infcloud/config.js"
ynh_replace_string "__TIMEZONE__" "$(cat /etc/timezone)" "$final_path/infcloud/config.js"
# Optional parameters from config-panel feature
if [ -n "$firstdayofweek" ]; then
ynh_replace_string "\(^var globalDatepickerFirstDayOfWeek=\).*" "\1$firstdayofweek;" "$final_path/infcloud/config.js"
fi
if [ -n "$activeview" ]; then
ynh_replace_string "\(^var globalActiveView=\).*" "\1\'$activeview\';" "$final_path/infcloud/config.js"
fi
if [ -n "$openformmode" ]; then
ynh_replace_string "\(^var globalOpenFormMode=\).*" "\1\'$openformmode\';" "$final_path/infcloud/config.js"
fi
if [ -n "$startofbusiness" ]; then
ynh_replace_string "\(^var globalCalendarStartOfBusiness=\).*" "\1$startofbusiness;" "$final_path/infcloud/config.js"
fi
if [ -n "$endofbusiness" ]; then
ynh_replace_string "\(^var globalCalendarEndOfBusiness=\).*" "\1$endofbusiness;" "$final_path/infcloud/config.js"
fi
if [ -n "$defaulteventduration" ]; then
ynh_replace_string "\(^var globalDefaultEventDuration=\).*" "\1$defaulteventduration;" "$final_path/infcloud/config.js"
fi
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$final_path/infcloud/config.js"
# Fix permission
chown -R radicale: $final_path
# Create php-fpm configuration
(cd scripts; ynh_add_fpm_config)
# Setup SSOWat
# Add /infcloud to the path of radicale to access it from the portal
# Replace radicale by InfCloud into YunoHost portal
ynh_app_setting_set $app path ${path_url%/}/infcloud
# Protect InfCloud access
ynh_app_setting_set $app protected_uris "/"
domain_regex=$(echo "$domain" | sed 's@-@.@g')
# Radicale is always accessible (For access to ressources)
ynh_app_setting_set $app skipped_regex "$domain_regex$path_url"
# Remove the previous entry for unprotected_uris
ynh_app_setting_delete $app unprotected_uris
else
# Remove InfCloud
# Get settings
path_url=$(dirname $(ynh_app_setting_get $app path))
# Remove InfCloud
ynh_secure_remove "$final_path/infcloud"
# Remove php-fpm configuration
ynh_remove_fpm_config
# Setup SSOWat
# Replace InfCloud by radicale into YunoHost portal
ynh_app_setting_set $app path $path_url
# Remove the previous entry for protected_uris and skipped_regex
ynh_app_setting_delete $app protected_uris
ynh_app_setting_delete $app skipped_regex
# Radicale is always accessible (For access to ressources)
ynh_app_setting_set $app unprotected_uris "/"
fi
# Regen ssowat configuration
yunohost app ssowatconf
# Update the config of the app
ynh_app_setting_set $app infcloud $infcloud