1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/lutim_ynh.git synced 2024-09-03 19:36:24 +02:00
lutim_ynh/scripts/upgrade

352 lines
13 KiB
Text
Raw Normal View History

2015-03-16 21:10:39 +01:00
#!/bin/bash
2017-03-19 19:16:10 +01:00
#=================================================
2021-05-16 16:48:58 +02:00
# GENERIC START
2017-03-19 19:16:10 +01:00
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2016-06-15 23:56:45 +02:00
2020-04-24 20:16:33 +02:00
source _common.sh
source /usr/share/yunohost/helpers
2017-03-19 19:16:10 +01:00
#=================================================
# LOAD SETTINGS
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Loading installation settings..." --weight=4
2017-03-19 19:16:10 +01:00
app=$YNH_APP_INSTANCE_NAME
2020-01-02 18:40:15 +01:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
2021-05-18 02:58:23 +02:00
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
2020-01-02 18:40:15 +01:00
port=$(ynh_app_setting_get --app=$app --key=port)
always_encrypt=$(ynh_app_setting_get --app=$app --key=always_encrypt)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
secret=$(ynh_app_setting_get --app=$app --key=secret)
overwrite_settings=$(ynh_app_setting_get --app=$app --key=overwrite_settings)
overwrite_nginx=$(ynh_app_setting_get --app=$app --key=overwrite_nginx)
overwrite_systemd=$(ynh_app_setting_get --app=$app --key=overwrite_systemd)
admin_mail_html=$(ynh_app_setting_get --app=$app --key=admin_mail_html)
2018-09-30 11:52:12 +02:00
# Optional parameters from config-panel feature
2020-01-02 18:40:15 +01:00
antiflood=$(ynh_app_setting_get --app=$app --key=antiflood)
delay=$(ynh_app_setting_get --app=$app --key=delay)
2015-03-16 21:10:39 +01:00
2017-12-16 23:22:54 +01:00
#=================================================
# CHECK VERSION
#=================================================
2021-05-16 16:48:58 +02:00
ynh_script_progression --message="Checking version..."
2017-12-16 23:22:54 +01:00
2018-07-13 17:33:54 +02:00
upgrade_type=$(ynh_check_app_version_changed)
2017-12-16 23:22:54 +01:00
2021-05-16 16:48:58 +02:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=15
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
ynh_clean_check_starting
# Restore it if the upgrade fails
ynh_restore_upgradebackup
2021-05-16 16:48:58 +02:00
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Activating maintenance mode..." --weight=2
ynh_maintenance_mode_ON
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name=$app --action="stop"
2017-03-19 19:16:10 +01:00
#=================================================
2018-09-30 11:52:12 +02:00
# ENSURE DOWNWARD COMPATIBILITY
2017-03-19 19:16:10 +01:00
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Ensuring downward compatibility..." --weight=2
2017-03-19 19:16:10 +01:00
2020-02-12 12:15:20 +01:00
# Fix is_public as a boolean
if [ "$is_public" = "Yes" ]; then
2020-04-24 19:59:27 +02:00
ynh_app_setting_set --app=$app --key=is_public --value=1
is_public=1
2020-02-12 12:15:20 +01:00
elif [ "$is_public" = "No" ]; then
2020-04-24 19:59:27 +02:00
ynh_app_setting_set --app=$app --key=is_public --value=0
is_public=0
2020-02-12 12:15:20 +01:00
fi
2020-02-13 16:14:56 +01:00
skipped_uris=$(ynh_app_setting_get --app=$app --key=skipped_uris)
# Unused with the permission system
2020-01-29 15:24:28 +01:00
if [ ! -z "$skipped_uris" ]; then
2020-04-24 19:59:27 +02:00
ynh_app_setting_delete --app=$app --key=skipped_uris
2017-03-19 19:16:10 +01:00
fi
2020-02-13 16:14:56 +01:00
# Create the permission "upload images" only if it doesn't exist.
if ! ynh_permission_exists --permission="upload images"
then
2020-04-24 19:59:27 +02:00
# This is a fake permission without any URL.
# The purpose of this permission is only to trigger hooks post_app_add/removeaccess when it's modified.
# We can't use a real permission for now because the actual permision system doesn't support regex.
ynh_permission_create --permission="upload images" --allowed="visitors"
if [ $is_public -eq 0 ]
then
# If the app is private, viewing images stays publicly accessible.
if [ "$path_url" == "/" ]; then
# If the path is /, clear it to prevent any error with the regex.
path_url=""
fi
# Modify the domain to be used in a regex
domain_regex=$(echo "$domain" | sed 's@-@.@g')
ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/stats/?$","$domain_regex$path_url/manifest.webapp/?$","$domain_regex$path_url/?$","$domain_regex$path_url/[d-m]/.*$"
# If the app is not public, then the "visitors" group doesn't have this permission
ynh_permission_update --permission="upload images" --remove="visitors"
fi
2020-02-13 16:14:56 +01:00
fi
2019-01-18 19:56:43 +01:00
# if final_path isn't set, which can happens with old scripts, set final_path.
2020-01-02 18:40:15 +01:00
if [ -z "$final_path" ]; then
2020-04-24 19:59:27 +02:00
final_path=/var/www/$app
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2016-03-31 23:26:35 +02:00
fi
2019-01-18 19:56:43 +01:00
# Fix always_encrypt as a boolean
2017-03-19 19:16:10 +01:00
if [ "$always_encrypt" = "Yes" ]; then
2020-04-24 19:59:27 +02:00
ynh_app_setting_set --app=$app --key=always_encrypt --value=1
always_encrypt=1
2017-03-19 19:16:10 +01:00
elif [ "$always_encrypt" = "No" ]; then
2020-04-24 19:59:27 +02:00
ynh_app_setting_set --app=$app --key=always_encrypt --value=0
always_encrypt=0
2017-03-19 19:16:10 +01:00
fi
2018-09-30 11:52:12 +02:00
# If overwrite_settings doesn't exist, create it
if [ -z "$overwrite_settings" ]; then
2020-04-24 19:59:27 +02:00
overwrite_settings=1
ynh_app_setting_set --app=$app --key=overwrite_settings --value=$overwrite_settings
2018-09-30 11:52:12 +02:00
fi
# If overwrite_nginx doesn't exist, create it
if [ -z "$overwrite_nginx" ]; then
2020-04-24 19:59:27 +02:00
overwrite_nginx=1
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=$overwrite_nginx
2018-09-30 11:52:12 +02:00
fi
# If overwrite_systemd doesn't exist, create it
if [ -z "$overwrite_systemd" ]; then
2020-04-24 19:59:27 +02:00
overwrite_systemd=1
ynh_app_setting_set --app=$app --key=overwrite_systemd --value=$overwrite_systemd
2018-09-30 11:52:12 +02:00
fi
# If secret doesn't exist, create it
if [ -z "$secret" ]; then
2020-04-24 19:59:27 +02:00
secret=$(grep "secrets *=>" "$final_path/lutim.conf" | cut -d\' -f2)
ynh_app_setting_set --app=$app --key=secret --value=$secret
2018-09-30 11:52:12 +02:00
fi
2019-01-31 11:53:22 +01:00
# Close opened port
if yunohost firewall list | grep -q "\- $port$"
then
2020-04-24 19:59:27 +02:00
ynh_exec_quiet yunohost firewall disallow TCP $port
2019-01-31 11:53:22 +01:00
fi
2020-03-12 18:54:58 +01:00
# Replace skipped_uris by unprotected_uris for the migration to the new permission system.
ynh_app_setting_delete --app=$app --key=skipped_uris
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
2017-03-19 19:16:10 +01:00
#=================================================
2021-05-16 16:48:58 +02:00
# CREATE DEDICATED USER
2018-05-20 20:55:15 +02:00
#=================================================
2021-05-16 16:48:58 +02:00
ynh_script_progression --message="Making sure dedicated system user exists..."
2018-05-20 20:55:15 +02:00
2021-05-16 16:48:58 +02:00
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
2018-05-20 20:55:15 +02:00
2017-03-19 19:16:10 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2019-01-13 19:10:28 +01:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2021-05-16 16:48:58 +02:00
ynh_script_progression --message="Upgrading source files..."
2017-03-19 19:16:10 +01:00
2021-05-16 16:48:58 +02:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
fi
2017-12-05 19:36:40 +01:00
2021-05-16 16:48:58 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
2017-12-05 19:36:40 +01:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=9
ynh_install_app_dependencies $pkg_dependencies
2017-03-19 19:16:10 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2016-06-15 23:56:45 +02:00
2018-09-30 11:52:12 +02:00
# Overwrite the nginx configuration only if it's allowed
if [ $overwrite_nginx -eq 1 ]
then
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
2020-04-24 19:59:27 +02:00
ynh_add_nginx_config
2018-09-30 11:52:12 +02:00
fi
2015-03-26 13:07:01 +01:00
2017-03-19 19:16:10 +01:00
#=================================================
# SPECIFIC UPGRADE
#=================================================
# SETUP LUTIM
#=================================================
ynh_script_progression --message="Reconfiguring $app..."
2017-03-19 19:16:10 +01:00
2018-09-30 11:52:12 +02:00
# Overwrite the settings config file only if it's allowed
if [ $overwrite_settings -eq 1 ]
then
2020-04-24 19:59:27 +02:00
# Configure Lutim
# Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
ynh_backup_if_checksum_is_different --file="$final_path/lutim.conf"
cp ../conf/lutim.conf.template "$final_path/lutim.conf"
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__ENCRYPT__" --replace_string="$always_encrypt" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$final_path/lutim.conf"
2020-01-02 18:42:16 +01:00
# Set the number of process for Lutim to twice the number of CPU core.
ynh_replace_string --match_string="__WORKERS__" --replace_string="$(( $(nproc) * 2 ))" --target_file="$final_path/lutim.conf"
2020-04-24 19:59:27 +02:00
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$final_path/lutim.conf"
# Optional parameters from config-panel feature
if [ -n "$antiflood" ]; then
ynh_replace_string --match_string=".*anti_flood_delay *=>.*" --replace_string=" anti_flood_delay => $antiflood," --target_file="$final_path/lutim.conf"
# Disable anti_flood_delay if the delay is 0
if [ $antiflood = 0 ]; then
ynh_replace_string --match_string="\(anti_flood_delay *=>.*\)" --replace_string="#\1" --target_file="$final_path/lutim.conf"
fi
fi
if [ -n "$delay" ]; then
ynh_replace_string --match_string=".*default_delay *=>.*" --replace_string=" default_delay => $delay," --target_file="$final_path/lutim.conf"
fi
2018-09-30 11:52:12 +02:00
fi
2015-03-16 21:10:39 +01:00
2020-01-29 15:24:28 +01:00
#=================================================
# SETUP HOOKS FILE
#=================================================
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../hooks/post_app_addaccess"
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../hooks/post_app_removeaccess"
2017-03-19 19:16:10 +01:00
#=================================================
# SETUP CRON
#=================================================
2015-03-16 21:10:39 +01:00
2021-04-22 22:46:29 +02:00
ynh_add_config --template="../conf/cron_lutim" --destination="/etc/cron.d/$app"
2015-03-16 21:10:39 +01:00
2017-03-19 19:16:10 +01:00
#=================================================
# UPDATE LUTIM WITH CARTON
#=================================================
2016-05-15 12:15:08 +02:00
2018-07-13 17:33:54 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading $app with Carton..." --weight=4
pushd "$final_path"
ynh_secure_remove --file="$final_path/local"
carton install --without=mysql --without=htpasswd --without=test
popd
2018-07-13 17:33:54 +02:00
fi
2017-03-19 19:16:10 +01:00
#=================================================
# SETUP SYSTEMD
#=================================================
# Overwrite the systemd configuration only if it's allowed
if [ $overwrite_systemd -eq 1 ]
then
ynh_script_progression --message="Upgrading systemd configuration..." --weight=2
ynh_add_systemd_config
fi
2017-03-19 19:16:10 +01:00
#=================================================
2021-05-16 16:48:58 +02:00
# GENERIC FINALIZATION
2017-03-19 19:16:10 +01:00
#=================================================
# SETUP LOGROTATE
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Upgrading logrotate configuration..."
2017-03-19 19:16:10 +01:00
2021-05-16 16:48:58 +02:00
# Use logrotate to manage app-specific logfile(s)
2017-09-08 13:10:22 +02:00
ynh_use_logrotate --non-append
chown $app -R /var/log/$app
2017-03-19 19:16:10 +01:00
#=================================================
2021-05-16 16:48:58 +02:00
# INTEGRATE SERVICE IN YUNOHOST
2020-11-23 08:45:29 +01:00
#=================================================
2021-05-16 16:48:58 +02:00
ynh_script_progression --message="Integrating service in YunoHost..."
2020-12-09 08:40:39 +01:00
yunohost service add $app --log="$final_path/log/production.log"
2020-11-23 08:45:29 +01:00
#=================================================
2021-05-16 16:48:58 +02:00
# START SYSTEMD SERVICE
2017-03-19 19:16:10 +01:00
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=4
2015-03-26 13:07:01 +01:00
ynh_systemd_action --service_name=$app --action="start" --line_match="Manager.*started" --log_path="/var/log/$app/production.log" --timeout="120"
2017-05-24 16:48:26 +02:00
#=================================================
2021-05-16 16:48:58 +02:00
# RELOAD NGINX
2017-05-24 16:48:26 +02:00
#=================================================
2021-05-16 16:48:58 +02:00
ynh_script_progression --message="Reloading NGINX web server..."
2017-05-24 16:48:26 +02:00
2021-05-16 16:48:58 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2018-05-20 20:55:15 +02:00
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Disabling maintenance mode..." --weight=7
2018-05-20 20:55:15 +02:00
ynh_maintenance_mode_OFF
2019-01-20 17:44:06 +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:27:17 +01:00
# Build the changelog
ynh_app_changelog || true
2019-01-20 17:44:06 +01:00
2019-01-30 19:27:17 +01:00
echo "You can find a config file at $final_path/lutim.conf
2019-01-20 17:44:06 +01:00
2019-01-30 19:27:17 +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/lutim_ynh__URL_TAG3__.
---
Changelog since your last upgrade:
$(cat changelog)" > mail_to_send
2020-01-02 18:40:15 +01:00
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=upgrade
2019-01-20 17:44:06 +01:00
2019-01-30 16:19:40 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Upgrade of $app completed" --last