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/upgrade

470 lines
16 KiB
Text
Raw Normal View History

2016-04-07 00:00:41 +02:00
#!/bin/bash
2017-03-19 18:36:20 +01:00
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2016-06-15 23:57:31 +02:00
2017-03-20 00:17:59 +01:00
source _common.sh
2016-12-14 16:13:20 +01:00
source /usr/share/yunohost/helpers
2017-03-19 18:36:20 +01:00
#=================================================
# LOAD SETTINGS
#=================================================
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Load settings" --weight=6
2017-03-19 18:36:20 +01:00
app=$YNH_APP_INSTANCE_NAME
2020-12-07 09:05:15 +01:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
admin=$(ynh_app_setting_get --app=$app --key=admin)
infcloud=$(ynh_app_setting_get --app=$app --key=infcloud)
language=$(ynh_app_setting_get --app=$app --key=language)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
version=$(ynh_app_setting_get --app=$app --key=version)
overwrite_logging=$(ynh_app_setting_get --app=$app --key=overwrite_logging)
overwrite_config=$(ynh_app_setting_get --app=$app --key=overwrite_config)
overwrite_infcloud=$(ynh_app_setting_get --app=$app --key=overwrite_infcloud)
overwrite_nginx=$(ynh_app_setting_get --app=$app --key=overwrite_nginx)
overwrite_phpfpm=$(ynh_app_setting_get --app=$app --key=overwrite_phpfpm)
2018-09-29 23:37:05 +02:00
# Optional parameters from config-panel feature
2020-12-07 09:05:15 +01:00
firstdayofweek=$(ynh_app_setting_get --app=$app --key=firstdayofweek)
activeview=$(ynh_app_setting_get --app=$app --key=activeview)
openformmode=$(ynh_app_setting_get --app=$app --key=openformmode)
startofbusiness=$(ynh_app_setting_get --app=$app --key=startofbusiness)
endofbusiness=$(ynh_app_setting_get --app=$app --key=endofbusiness)
defaulteventduration=$(ynh_app_setting_get --app=$app --key=defaulteventduration)
2017-03-19 18:36:20 +01:00
2017-12-16 23:29:00 +01:00
#=================================================
# CHECK VERSION
#=================================================
2018-07-13 17:36:34 +02:00
upgrade_type=$(ynh_check_app_version_changed)
2017-12-16 23:29:00 +01:00
2021-08-17 07:56:49 +02:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backup the app before upgrading"
# 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
2017-03-19 18:36:20 +01:00
#=================================================
2018-07-13 17:36:34 +02:00
# ENSURE DOWNWARD COMPATIBILITY
2017-03-19 18:36:20 +01:00
#=================================================
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Ensure downward compatibility"
2017-03-19 18:36:20 +01:00
2017-07-01 16:42:57 +02:00
ynh_app_setting_delete $app unprotected_regex
2017-03-19 18:36:20 +01:00
if [ -d /usr/local/radicale ]
then
2017-09-05 00:34:00 +02:00
mkdir -p /opt/yunohost
mv /usr/local/radicale /opt/yunohost/
2017-03-19 18:36:20 +01:00
fi
if [ -z "$version" ]
then
2019-01-18 21:12:58 +01:00
# Retrieve the version number in the manifest file.
version=$(ynh_app_upstream_version)
2017-06-13 22:28:52 +02:00
ynh_app_setting_set $app version "$version"
2017-03-19 18:36:20 +01:00
fi
2019-01-18 21:12:58 +01:00
# Fix infcloud as a boolean
2017-03-19 18:36:20 +01:00
if [ "$infcloud" = "Yes" ]; then
2019-01-18 21:12:58 +01:00
ynh_app_setting_set $app infcloud 1
2017-03-19 18:36:20 +01:00
infcloud=1
elif [ "$infcloud" = "No" ]; then
ynh_app_setting_set $app infcloud 0
infcloud=0
fi
2018-09-29 23:37:05 +02:00
# If overwrite_logging doesn't exist, create it
if [ -z "$overwrite_logging" ]; then
overwrite_logging=1
ynh_app_setting_set $app overwrite_logging $overwrite_logging
fi
# If overwrite_config doesn't exist, create it
if [ -z "$overwrite_config" ]; then
overwrite_config=1
ynh_app_setting_set $app overwrite_config $overwrite_config
fi
# If overwrite_infcloud doesn't exist, create it
if [ -z "$overwrite_infcloud" ]; then
overwrite_infcloud=1
ynh_app_setting_set $app overwrite_infcloud $overwrite_infcloud
fi
# If overwrite_nginx doesn't exist, create it
if [ -z "$overwrite_nginx" ]; then
overwrite_nginx=1
ynh_app_setting_set $app overwrite_nginx $overwrite_nginx
fi
# If overwrite_phpfpm doesn't exist, create it
if [ -z "$overwrite_phpfpm" ]; then
overwrite_phpfpm=1
ynh_app_setting_set $app overwrite_phpfpm $overwrite_phpfpm
fi
#=================================================
# Migrate legacy permissions to new system
#=================================================
if ynh_legacy_permissions_exists
then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
2017-03-19 18:36:20 +01:00
#=================================================
# CHECK THE PATH
#=================================================
2016-08-12 14:25:56 +02:00
2017-03-19 18:36:20 +01:00
if [ $infcloud -eq 1 ]; then
2019-01-18 21:12:58 +01:00
# Remove /infcloud to deal with the path only.
path_url=$(echo $path_url | sed "s@/infcloud@@")
2016-08-05 17:00:50 +02:00
fi
2016-04-07 00:00:41 +02:00
2018-07-13 17:36:34 +02:00
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
2021-08-17 07:56:49 +02:00
ynh_script_progression --message="Activate maintenance mode" --weight=1
2018-07-13 17:36:34 +02:00
ynh_maintenance_mode_ON
2017-03-19 18:36:20 +01:00
#=================================================
# STANDARD UPGRADE STEPS
2019-01-31 14:27:16 +01:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2021-08-17 07:56:49 +02:00
ynh_script_progression --message="Upgrade dependencies" --weight=5
2019-01-31 14:27:16 +01:00
2020-12-07 09:05:15 +01:00
ynh_install_app_dependencies $pkg_dependencies
2019-01-31 14:27:16 +01:00
2017-03-19 18:36:20 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-12-07 09:05:15 +01:00
# Overwrite the NGINX configuration only if it's allowed
2018-09-29 23:37:05 +02:00
if [ $overwrite_nginx -eq 1 ]
then
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Reconfigure nginx" --weight=2
2018-09-29 23:37:05 +02:00
ynh_add_nginx_config
if [ $infcloud -eq 1 ]
2019-01-18 21:12:58 +01:00
then
2020-12-07 09:05:15 +01:00
# Add InfCloud in NGINX config
2018-09-29 23:37:05 +02:00
ynh_replace_string "#INFCLOUD#" "" /etc/nginx/conf.d/$domain.d/$app.conf
fi
2021-07-26 07:43:39 +02:00
ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf"
2017-03-19 18:36:20 +01:00
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
2021-08-17 07:56:49 +02:00
ynh_script_progression --message="Create a dedicated user" --weight=2
2017-03-19 18:36:20 +01:00
2019-01-18 21:12:58 +01:00
# Create a dedicated user (if not existing)
ynh_system_user_create $app
2017-03-19 18:36:20 +01:00
if [ $infcloud -eq 1 ]
2016-04-07 00:00:41 +02:00
then
2017-03-19 18:36:20 +01:00
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
2018-09-29 23:37:05 +02:00
# Overwrite the php-fpm configuration only if it's allowed
if [ $overwrite_phpfpm -eq 1 ]
then
2020-12-07 09:05:15 +01:00
ynh_script_progression --message="Reconfigure PHP-FPM" --weight=2
2019-01-18 21:12:58 +01:00
# Create a dedicated php-fpm config
ynh_add_fpm_config
2018-09-29 23:37:05 +02:00
fi
2016-04-07 00:00:41 +02:00
fi
2017-03-19 18:36:20 +01:00
#=================================================
# SPECIFIC UPGRADE
#=================================================
# UPGRADE RADICALE IN ITS VIRTUALENV
#=================================================
2018-07-13 17:36:34 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Upgrade Radicale in its virtualenv" --weight=6
2018-07-13 17:36:34 +02:00
# Upgrade pip packages
ynh_secure_remove /opt/yunohost/$app
virtualenv /opt/yunohost/$app
version=$(ynh_app_setting_get $app version $version)
bash -c "source /opt/yunohost/radicale/bin/activate && pip install radicale==$version python-ldap"
fi
2017-03-19 18:36:20 +01:00
#=================================================
# COPY FILES INTO $FINAL_PATH
#=================================================
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Download, check and unpack source"
2016-04-07 00:00:41 +02:00
# Copy files to the right place
2017-09-05 00:34:00 +02:00
mkdir -p $final_path/collections
cp ../conf/radicale.wsgi $final_path
2019-01-18 21:12:58 +01:00
# Copy extra files
2017-09-05 00:34:00 +02:00
cp -a ../sources/extra_files_radicale/. "$final_path"
2019-01-18 21:12:58 +01:00
# regex.py file is patched to fix the awful commit e807c3d35bea9cfcfcacac83b1b17d748ea15a39 that stop the reading of "rights" file after the first match.
2017-09-05 00:34:00 +02:00
mv "$final_path/regex.py" /opt/yunohost/$app/lib/python*/site-packages/radicale/rights/regex.py
2018-07-13 17:36:34 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
if [ "$infcloud" = "1" ]
2019-01-18 21:12:58 +01:00
then
#Instal InfCloud
# Backup the content of $final_path
final_path_backup=$final_path
# Modify final_path for InfCloud installation
final_path=$final_path/infcloud
2018-09-29 23:37:05 +02:00
# If overwrite_infcloud is 0, copy the config file, then restore it.
if [ $overwrite_infcloud -eq 0 ]; then
cp -a $final_path/config.js ./config.js
fi
2019-01-18 21:12:58 +01:00
# Download and uncompress the source into final_path
ynh_setup_source "$final_path"
2018-09-29 23:37:05 +02:00
if [ $overwrite_infcloud -eq 0 ]; then
mv ./config.js $final_path/config.js
fi
2019-01-18 21:12:58 +01:00
# Restore the content of $final_path
final_path=$final_path_backup
2018-07-13 17:36:34 +02:00
fi
2016-04-07 00:00:41 +02:00
fi
2017-03-19 18:36:20 +01:00
#=================================================
# CONFIGURE RADICALE
#=================================================
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Reconfigure Radicale" --weight=5
2017-03-19 18:36:20 +01:00
2018-09-29 23:37:05 +02:00
# Overwrite the logging config file only if it's allowed
if [ $overwrite_logging -eq 1 ]
then
2019-01-18 21:12:58 +01:00
# Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
ynh_backup_if_checksum_is_different "/etc/$app/logging"
2018-09-29 23:37:05 +02:00
cp ../conf/logging /etc/$app/
2019-01-18 21:12:58 +01:00
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "/etc/$app/logging"
2018-09-29 23:37:05 +02:00
fi
# Overwrite the config file only if it's allowed
if [ $overwrite_config -eq 1 ]
then
2019-01-18 21:12:58 +01:00
# Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
ynh_backup_if_checksum_is_different "/etc/$app/config"
2018-09-29 23:37:05 +02:00
cp ../conf/config /etc/$app/
ynh_replace_string "__PATH__" "${path_url%/}" /etc/$app/config
ynh_replace_string "__FINALPATH__" "$final_path" /etc/$app/config
2019-01-18 21:12:58 +01:00
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "/etc/$app/config"
2018-09-29 23:37:05 +02:00
fi
# Overwrite the InfCloud config file only if it's allowed
if [ $overwrite_infcloud -eq 1 ]
then
if [ $infcloud -eq 1 ]
2019-01-18 21:12:58 +01:00
then
# InfCloud configuration
# Set language
2018-09-29 23:37:05 +02:00
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
ynh_app_setting_set $app language $language
2019-01-18 21:12:58 +01:00
# Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
ynh_backup_if_checksum_is_different "$final_path/infcloud/config.js"
2018-09-29 23:37:05 +02:00
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
2019-01-18 21:12:58 +01:00
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$final_path/infcloud/config.js"
2018-09-29 23:37:05 +02:00
fi
2016-04-07 00:00:41 +02:00
fi
2017-03-19 18:36:20 +01:00
#=================================================
2019-01-18 21:12:58 +01:00
# SET PERMISSIONS ON RADICALE DIRECTORIES
2017-03-19 18:36:20 +01:00
#=================================================
2016-04-07 00:00:41 +02:00
2017-09-05 00:34:00 +02:00
chown radicale: -R /opt/yunohost/$app
2016-08-05 21:20:14 +02:00
2016-04-07 00:00:41 +02:00
# Fix permission
2017-09-05 00:34:00 +02:00
chmod 755 /etc/$app/
find /opt/yunohost/$app/ -type d -exec chmod 2755 {} \;
find /opt/yunohost/$app/ -type f -exec chmod g+r,o+r {} \;
chmod 644 /etc/$app/*
chown -R radicale: $final_path
mkdir -p /var/log/$app
touch /var/log/$app/$app.log
chown radicale -R /var/log/$app
2019-01-18 21:12:58 +01:00
# Set default permissions as radicale do.
2017-09-05 00:34:00 +02:00
chmod 666 -R $final_path/default_collections
chmod 777 $final_path/default_collections $final_path/default_collections/USER
2016-04-07 00:00:41 +02:00
2017-03-19 18:36:20 +01:00
#=================================================
# CONFIGURE UWSGI FOR RADICALE
#=================================================
2017-09-05 00:34:00 +02:00
cp ../conf/radicale.ini /etc/uwsgi/apps-available/
2017-03-19 18:36:20 +01:00
#=================================================
2020-12-07 09:05:15 +01:00
# ADVERTISE SERVICE IN ADMIN PANEL
2017-03-19 18:36:20 +01:00
#=================================================
2020-12-07 09:05:15 +01:00
ynh_script_progression --message="Restart Radicale" --weight=2
2017-03-19 18:36:20 +01:00
2019-01-18 21:12:58 +01:00
ynh_systemd_action --action=restart --service_name=uwsgi
2020-12-07 09:05:15 +01:00
yunohost service add uwsgi --log="/var/log/uwsgi/app/radicale.log"
2017-03-19 18:36:20 +01:00
#=================================================
# PREPARE THE HOOKS
#=================================================
2019-01-18 21:12:58 +01:00
# Modify the hooks for create user collections and to remove them.
2017-06-13 22:28:52 +02:00
ynh_replace_string "__FINALPATH__" "$final_path" ../hooks/post_user_create
ynh_replace_string "__FINALPATH__" "$final_path" ../hooks/post_user_delete
2017-03-19 18:36:20 +01:00
2018-07-13 17:36:34 +02:00
#=================================================
# SETUP LOGROTATE
#=================================================
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Reconfigure logrotate" --weight=3
2018-07-13 17:36:34 +02:00
ynh_use_logrotate --non-append
2017-03-19 18:36:20 +01:00
#=================================================
# GENERIC FINALISATION
#=================================================
# SETUP SSOWAT
#=================================================
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Reconfigure SSOwat" --weight=2
2017-03-19 18:36:20 +01:00
if [ $infcloud -eq 1 ]
2019-01-18 21:12:58 +01:00
then
# 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 "/"
2017-03-19 18:36:20 +01:00
domain_regex=$(echo "$domain" | sed 's@-@.@g')
2019-01-18 21:12:58 +01:00
# Radicale is always accessible (For access to ressources)
ynh_app_setting_set $app skipped_regex "$domain_regex$path_url"
else
# If only radicale is installed
# Radicale is always accessible (For access to ressources)
ynh_app_setting_set $app unprotected_uris "/"
2016-04-07 00:00:41 +02:00
fi
2017-03-19 18:36:20 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2020-12-07 09:05:15 +01:00
ynh_script_progression --message="Reload NGINX"
2017-03-19 18:36:20 +01:00
2019-01-18 21:12:58 +01:00
ynh_systemd_action --action=reload --service_name=nginx
2018-08-05 19:16:26 +02:00
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Disable maintenance mode" --weight=5
2018-08-05 19:16:26 +02:00
ynh_maintenance_mode_OFF
2019-01-21 13:22:56 +01:00
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
# Get main domain and buid the url of the admin panel of the app.
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
2019-01-30 19:30:41 +01:00
# Build the changelog
ynh_app_changelog || true
2019-01-21 13:22:56 +01:00
if [ $infcloud -eq 1 ]
then
infcloud_config="
InfCloud has its own config file, at $final_path/infcloud/config.js
"
else
infcloud_config=""
fi
2019-01-30 19:30:41 +01:00
echo "Use the file /etc/radicale/config to change the main configuration of radicale.
2019-01-21 13:22:56 +01:00
The file /etc/radicale/logging to change the level of logging.
And the file /etc/radicale/rights to edit the way the calendars will be shared.
$infcloud_config
2019-01-30 19:30:41 +01:00
You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.
You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__.
If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/radicale_ynh__URL_TAG3__.
---
Changelog since your last upgrade:
$(cat changelog)" > mail_to_send
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="$admin" --type="upgrade"
2019-01-21 13:22:56 +01:00
2019-01-30 19:16:04 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2019-01-21 13:22:56 +01:00
2019-01-30 19:16:04 +01:00
ynh_script_progression --message="Upgrade completed" --last