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

471 lines
17 KiB
Text
Raw Permalink Normal View History

2016-04-07 00:00:41 +02:00
#!/bin/bash
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
# GENERIC START
2017-03-19 18:36:20 +01:00
#=================================================
# 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
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Loading installation settings..."
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)
language=$(ynh_app_setting_get --app=$app --key=language)
2022-03-18 22:47:33 +01:00
admin=$(ynh_app_setting_get --app=$app --key=admin)
2020-12-07 09:05:15 +01:00
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
2022-11-22 13:40:41 +01:00
port=$(ynh_app_setting_get --app=$app --key=port)
2022-03-18 22:47:33 +01:00
infcloud=$(ynh_app_setting_get --app=$app --key=infcloud)
2020-12-07 09:05:15 +01:00
version=$(ynh_app_setting_get --app=$app --key=version)
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)
2022-11-22 13:40:41 +01:00
overwrite_systemd=$(ynh_app_setting_get --app=$app --key=overwrite_systemd)
2020-12-07 09:05:15 +01:00
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
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Checking version..."
2017-12-16 23:29:00 +01:00
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
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
2021-08-17 07:56:49 +02:00
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
2022-11-22 13:40:41 +01:00
ynh_clean_check_starting
# Restore it if the upgrade fails
ynh_restore_upgradebackup
2021-08-17 07:56:49 +02:00
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2022-03-18 22:47:33 +01:00
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Activate maintenance mode"
ynh_maintenance_mode_ON
#=================================================
# STANDARD UPGRADE STEPS
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
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Ensuring downward compatibility..."
2017-03-19 18:36:20 +01:00
2022-03-18 22:47:33 +01:00
ynh_app_setting_delete --app=$app --key=unprotected_regex
2017-07-01 16:42:57 +02:00
2017-03-19 18:36:20 +01:00
if [ -d /usr/local/radicale ]
then
2022-11-22 13:40:41 +01:00
mkdir -p /opt/yunohost
mv /usr/local/radicale /opt/yunohost/
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
2022-11-22 13:40:41 +01:00
ynh_app_setting_set --app=$app --key=infcloud --value=1
infcloud=1
2017-03-19 18:36:20 +01:00
elif [ "$infcloud" = "No" ]; then
2022-11-22 13:40:41 +01:00
ynh_app_setting_set --app=$app --key=infcloud --value=0
infcloud=0
2018-09-29 23:37:05 +02:00
fi
# If overwrite_config doesn't exist, create it
if [ -z "$overwrite_config" ]; then
2022-11-22 13:40:41 +01:00
overwrite_config=1
ynh_app_setting_set --app=$app --key=overwrite_config --value=$overwrite_config
2018-09-29 23:37:05 +02:00
fi
# If overwrite_infcloud doesn't exist, create it
if [ -z "$overwrite_infcloud" ]; then
2022-11-22 13:40:41 +01:00
overwrite_infcloud=1
ynh_app_setting_set --app=$app --key=overwrite_infcloud --value=$overwrite_infcloud
2018-09-29 23:37:05 +02:00
fi
# If overwrite_nginx doesn't exist, create it
if [ -z "$overwrite_nginx" ]; then
2022-11-22 13:40:41 +01:00
overwrite_nginx=1
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=$overwrite_nginx
fi
# If overwrite_systemd doesn't exist, create it
if [ -z "$overwrite_systemd" ]; then
overwrite_systemd=1
ynh_app_setting_set --app=$app --key=overwrite_systemd --value=$overwrite_systemd
2018-09-29 23:37:05 +02:00
fi
# If overwrite_phpfpm doesn't exist, create it
if [ -z "$overwrite_phpfpm" ]; then
2022-11-22 13:40:41 +01:00
overwrite_phpfpm=1
ynh_app_setting_set --app=$app --key=overwrite_phpfpm --value=$overwrite_phpfpm
2018-09-29 23:37:05 +02:00
fi
2022-03-18 22:47:33 +01:00
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
2022-11-22 13:40:41 +01:00
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
# If path_url still contains infcloud, then radicale_path doesn't exist
if [[ "$path_url" =~ "/infcloud" ]]; then
path_url="${path_url%/*}"
ynh_app_setting_set --app=$app --key=path --value=$path_url
fi
2022-11-22 13:40:41 +01:00
# Migrate to v2
if ynh_compare_current_package_version --comparison le --version 1.1.6~ynh6
then
ynh_print_warn --message="Migration to radicale v2+..."
# Force nginx upgrade
overwrite_nginx=1
# Force systemd upgrade
overwrite_systemd=1
# Force config upgrade
overwrite_config=1
# Migrate collections to v2 format
# Init a new temporary virtualenv
virtualenv -p python3 /opt/yunohost/radicale_v1_temp
# Install a v1 version
/opt/yunohost/radicale_v1_temp/bin/pip install radicale==1.1.* python-ldap
# Force the migration of calendars
if ! ynh_exec_warn /opt/yunohost/radicale_v1_temp/bin/python3 -m radicale --export-storage "$final_path/collections_new"
then
# Clean up if it fails to prevent further failures
ynh_secure_remove --file="/opt/yunohost/radicale_v1_temp"
ynh_secure_remove --file="$final_path/collections_new"
fi
# Backup the old collection
mv "$final_path/collections" "$final_path/collections_v1"
# And replace by the new one
mv "$final_path/collections_new" "$final_path/collections"
# Find a free port
port=$(ynh_find_port --port=5232)
ynh_app_setting_set --app=$app --key=port --value=$port
## Cleanup...
ynh_secure_remove --file="$final_path/default_collections"
ynh_secure_remove --file="$final_path/collections.props"
# Remove the temporary virtualenv
ynh_secure_remove --file="/opt/yunohost/radicale_v1_temp"
# Remove uwsgi config
ynh_secure_remove --file="$final_path/radicale.wsgi"
ynh_secure_remove --file="/etc/uwsgi/apps-enabled/radicale.ini"
ynh_secure_remove --file="/etc/uwsgi/apps-available/radicale.ini"
ynh_systemd_action --service_name=uwsgi --action="restart"
# Set permissions
if [ $infcloud -eq 1 ]
then
ynh_permission_create --permission="infcloud" --url="${path_url%/}/infcloud" --allowed="$admin" --show_tile=true
fi
ynh_permission_update --permission="main" --add="visitors" --show_tile=false
fi
2022-11-22 13:40:41 +01:00
2018-07-13 17:36:34 +02:00
#=================================================
2022-03-18 22:47:33 +01:00
# CREATE DEDICATED USER
2018-07-13 17:36:34 +02:00
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Making sure dedicated system user exists..."
2018-07-13 17:36:34 +02:00
2022-03-18 22:47:33 +01:00
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
2018-07-13 17:36:34 +02:00
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2019-01-31 14:27:16 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2022-11-22 13:40:41 +01:00
ynh_script_progression --message="Upgrading source files..."
# Copy files to the right place
mkdir -p $final_path/collections
if [ $infcloud -eq 1 ]
then
# Download and uncompress the source into final_path
ynh_setup_source --dest_dir="$final_path/infcloud" --keep="config.js"
fi
2022-03-18 22:47:33 +01:00
fi
2022-11-22 13:40:41 +01:00
chmod 750 -R "$final_path"
2022-03-18 22:47:33 +01:00
chown -R $app:www-data "$final_path"
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
2022-11-22 13:40:41 +01:00
ynh_script_progression --message="Upgrading NGINX web server configuration..."
# Create a dedicated NGINX config
ynh_add_nginx_config
if [ $infcloud -eq 1 ]
then
# Add InfCloud in NGINX config
ynh_replace_string --match_string="#INFCLOUD#" --replace_string="" --target_file="/etc/nginx/conf.d/$domain.d/$app.conf"
fi
ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf"
2017-03-19 18:36:20 +01:00
fi
#=================================================
2022-03-18 22:47:33 +01:00
# UPGRADE DEPENDENCIES
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Upgrading dependencies..."
2017-03-19 18:36:20 +01:00
2022-03-18 22:47:33 +01:00
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
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
2022-11-22 13:40:41 +01:00
# Overwrite the php-fpm configuration only if it's allowed
if [ $overwrite_phpfpm -eq 1 ]
then
ynh_script_progression --message="Upgrading PHP-FPM configuration..."
2022-03-18 22:47:33 +01:00
2022-11-22 13:40:41 +01:00
# Create a dedicated PHP-FPM config
ynh_add_fpm_config
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
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
2022-11-22 13:40:41 +01:00
ynh_script_progression --message="Upgrade Radicale in its virtualenv"
# Upgrade pip packages
ynh_secure_remove --file="/opt/yunohost/$app"
virtualenv -p python3 /opt/yunohost/$app
version=$(ynh_app_upstream_version)
ynh_app_setting_set --app=$app --key=version --value="$version"
/opt/yunohost/$app/bin/python3 -m pip install radicale==$version passlib bcrypt
# Add LDAP plugin
# (cd /opt/yunohost/$app
# set +u; source bin/activate
# # git clone https://github.com/marcoh00/radicale-auth-ldap
# git clone https://github.com/cloudron-io/radicale-auth-ldap
# cd radicale-auth-ldap
# python3 -m pip install .)
# Use htpasswd instead of ldap
touch /etc/radicale/users
2018-07-13 17:36:34 +02:00
fi
2017-03-19 18:36:20 +01:00
2022-03-18 22:47:33 +01:00
chown radicale: -R /opt/yunohost/$app
2022-11-22 13:40:41 +01:00
2022-03-18 22:47:33 +01:00
find /opt/yunohost/$app/ -type d -exec chmod 2755 {} \;
find /opt/yunohost/$app/ -type f -exec chmod g+r,o+r {} \;
2016-04-07 00:00:41 +02:00
2017-03-19 18:36:20 +01:00
#=================================================
# CONFIGURE RADICALE
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Reconfigure Radicale"
2017-03-19 18:36:20 +01:00
2018-09-29 23:37:05 +02:00
# Overwrite the config file only if it's allowed
if [ $overwrite_config -eq 1 ]
then
2022-11-22 13:40:41 +01:00
ynh_add_config --template="../conf/config" --destination="/etc/$app/config"
2018-09-29 23:37:05 +02:00
fi
2022-03-18 22:47:33 +01:00
chmod 755 /etc/$app/
chmod 644 /etc/$app/*
2018-09-29 23:37:05 +02:00
# Overwrite the InfCloud config file only if it's allowed
2022-03-20 14:04:52 +01:00
if [ $infcloud -eq 1 ]
2018-09-29 23:37:05 +02:00
then
2022-11-22 13:40:41 +01:00
if [ $overwrite_infcloud -eq 1 ]
then
# 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
ynh_app_setting_set --app=$app --key=language --value=$language
timezone=$(cat /etc/timezone)
ynh_add_config --template="../conf/config.js" --destination="$final_path/infcloud/config.js"
# Optional parameters from config-panel feature
if [ -n "$firstdayofweek" ]; then
ynh_replace_string --match_string="\(^var globalDatepickerFirstDayOfWeek=\).*" --replace_string="\1$firstdayofweek;" --target_file="$final_path/infcloud/config.js"
fi
if [ -n "$activeview" ]; then
ynh_replace_string --match_string="\(^var globalActiveView=\).*" --replace_string="\1\'$activeview\';" --target_file="$final_path/infcloud/config.js"
fi
if [ -n "$openformmode" ]; then
ynh_replace_string --match_string="\(^var globalOpenFormMode=\).*" --replace_string="\1\'$openformmode\';" --target_file="$final_path/infcloud/config.js"
fi
if [ -n "$startofbusiness" ]; then
ynh_replace_string --match_string="\(^var globalCalendarStartOfBusiness=\).*" --replace_string="\1$startofbusiness;" --target_file="$final_path/infcloud/config.js"
fi
if [ -n "$endofbusiness" ]; then
ynh_replace_string --match_string="\(^var globalCalendarEndOfBusiness=\).*" --replace_string="\1$endofbusiness;" --target_file="$final_path/infcloud/config.js"
fi
if [ -n "$defaulteventduration" ]; then
ynh_replace_string --match_string="\(^var globalDefaultEventDuration=\).*" --replace_string="\1$defaulteventduration;" --target_file="$final_path/infcloud/config.js"
fi
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$final_path/infcloud/config.js"
chmod 440 "$final_path/infcloud/config.js"
chown $app:www-data "$final_path/infcloud/config.js"
fi
2016-04-07 00:00:41 +02:00
fi
2022-03-18 22:47:33 +01:00
#=================================================
# GENERIC FINALIZATION
2018-07-13 17:36:34 +02:00
#=================================================
# SETUP LOGROTATE
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Upgrading logrotate configuration..."
mkdir -p /var/log/$app
touch /var/log/$app/$app.log
chown radicale -R /var/log/$app
2018-07-13 17:36:34 +02:00
2022-03-18 22:47:33 +01:00
# Use logrotate to manage app-specific logfile(s)
2018-07-13 17:36:34 +02:00
ynh_use_logrotate --non-append
2022-11-22 13:40:41 +01:00
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=2
# Overwrite the systemd configuration only if it's allowed
if [ $overwrite_systemd -eq 1 ]
then
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="../conf/systemd.service"
ynh_add_systemd_config
fi
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
# INTEGRATE SERVICE IN YUNOHOST
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Integrating service in YunoHost..."
2022-11-22 13:40:41 +01:00
yunohost service add $app --log="/var/log/$app"
2022-03-18 22:47:33 +01:00
2017-03-19 18:36:20 +01:00
#=================================================
2022-03-18 22:47:33 +01:00
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
2017-03-19 18:36:20 +01:00
2022-11-22 13:40:41 +01:00
# ynh_systemd_action --service_name=uwsgi --action="restart"
ynh_systemd_action --service_name=$app --action="restart"
2016-04-07 00:00:41 +02:00
2017-03-19 18:36:20 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Reloading NGINX web server..."
2017-03-19 18:36:20 +01:00
2022-03-18 22:47:33 +01:00
ynh_systemd_action --service_name=nginx --action=reload
2018-08-05 19:16:26 +02:00
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Disable maintenance mode"
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
2022-11-22 13:40:41 +01:00
infcloud_config="
2019-01-21 13:22:56 +01:00
InfCloud has its own config file, at $final_path/infcloud/config.js
"
else
2022-11-22 13:40:41 +01:00
infcloud_config=""
2019-01-21 13:22:56 +01:00
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
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
2022-03-18 22:47:33 +01:00
ynh_script_progression --message="Upgrade of $app completed"