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-12-16 23:22:54 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
|
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
|
|
|
#=================================================
|
|
|
|
# ACTIVATE MAINTENANCE MODE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Activating maintenance mode..." --weight=2
|
|
|
|
|
|
|
|
ynh_maintenance_mode_ON
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
2022-06-23 08:54:56 +02:00
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
2019-01-18 19:56:43 +01:00
|
|
|
# Fix always_encrypt as a boolean
|
2023-05-20 20:29:05 +02:00
|
|
|
if [ "${always_encrypt:-}" = "Yes" ]; then
|
2022-07-28 22:53:10 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=always_encrypt --value=1
|
|
|
|
always_encrypt=1
|
2023-05-20 20:29:05 +02:00
|
|
|
elif [ "${always_encrypt:-}" = "No" ]; then
|
2022-07-28 22:53:10 +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
|
2023-05-20 20:29:05 +02:00
|
|
|
if [ -z "${overwrite_settings:-}" ]; then
|
2022-07-28 22:53:10 +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
|
2023-05-20 20:29:05 +02:00
|
|
|
if [ -z "${overwrite_nginx:-}" ]; then
|
2022-07-28 22:53:10 +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
|
2023-05-20 20:29:05 +02:00
|
|
|
if [ -z "${overwrite_systemd:-}" ]; then
|
2022-07-28 22:53:10 +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
|
2023-05-20 20:29:05 +02:00
|
|
|
if [ -z "${secret:-}" ]; then
|
|
|
|
secret=$(grep "secrets *=>" "$install_dir/lutim.conf" | cut -d\' -f2)
|
2022-07-28 22:53:10 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=secret --value=$secret
|
2018-09-30 11:52:12 +02:00
|
|
|
fi
|
|
|
|
|
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
|
2023-05-20 20:29:05 +02:00
|
|
|
ynh_setup_source --dest_dir="$install_dir"
|
2021-05-16 16:48:58 +02:00
|
|
|
fi
|
2017-12-05 19:36:40 +01:00
|
|
|
|
2023-05-20 20:29:05 +02:00
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:www-data "$install_dir"
|
2022-06-23 08:54:56 +02:00
|
|
|
|
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
|
2022-07-28 22:53:10 +02:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
|
|
|
|
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
|
|
|
|
#=================================================
|
2020-11-13 12:45:25 +01:00
|
|
|
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
|
2022-07-28 22:53:10 +02:00
|
|
|
workers="$(( $(nproc) * 2 ))"
|
2023-05-20 20:29:05 +02:00
|
|
|
ynh_add_config --template="../conf/lutim.conf.template" --destination="$install_dir/lutim.conf"
|
2022-07-28 22:53:10 +02:00
|
|
|
|
2023-05-20 20:29:05 +02:00
|
|
|
chmod 400 "$install_dir/lutim.conf"
|
|
|
|
chown $app:$app "$install_dir/lutim.conf"
|
2022-07-28 22:53:10 +02:00
|
|
|
|
|
|
|
# Optional parameters from config-panel feature
|
2023-05-20 20:29:05 +02:00
|
|
|
if [ -n "${antiflood:-}" ]; then
|
|
|
|
ynh_replace_string --match_string=".*anti_flood_delay *=>.*" --replace_string=" anti_flood_delay => $antiflood," --target_file="$install_dir/lutim.conf"
|
2022-07-28 22:53:10 +02:00
|
|
|
# Disable anti_flood_delay if the delay is 0
|
|
|
|
if [ $antiflood = 0 ]; then
|
2023-05-20 20:29:05 +02:00
|
|
|
ynh_replace_string --match_string="\(anti_flood_delay *=>.*\)" --replace_string="#\1" --target_file="$install_dir/lutim.conf"
|
2022-07-28 22:53:10 +02:00
|
|
|
fi
|
|
|
|
fi
|
2023-05-20 20:29:05 +02:00
|
|
|
if [ -n "${delay:-}" ]; then
|
|
|
|
ynh_replace_string --match_string=".*default_delay *=>.*" --replace_string=" default_delay => $delay," --target_file="$install_dir/lutim.conf"
|
2022-07-28 22:53:10 +02:00
|
|
|
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
|
2022-07-28 22:53:10 +02:00
|
|
|
ynh_script_progression --message="Upgrading $app with Carton..." --weight=4
|
2023-05-20 20:29:05 +02:00
|
|
|
pushd "$install_dir"
|
|
|
|
ynh_secure_remove --file="$install_dir/local"
|
2022-07-28 22:53:10 +02:00
|
|
|
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
|
|
|
|
2022-06-23 08:54:56 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Overwrite the systemd configuration only if it's allowed
|
|
|
|
if [ $overwrite_systemd -eq 1 ]
|
|
|
|
then
|
2022-07-28 22:53:10 +02:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --weight=2
|
|
|
|
ynh_add_systemd_config
|
2022-06-23 08:54:56 +02:00
|
|
|
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..."
|
2022-06-23 08:54:56 +02:00
|
|
|
|
2023-05-20 20:29:05 +02:00
|
|
|
yunohost service add $app --log="$install_dir/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
|
|
|
#=================================================
|
2022-06-23 08:54:56 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=4
|
2015-03-26 13:07:01 +01:00
|
|
|
|
2022-06-23 08:54:56 +02: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
|
|
|
|
2018-05-20 20:55:15 +02:00
|
|
|
#=================================================
|
|
|
|
# DEACTIVE MAINTENANCE MODE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_maintenance_mode_OFF
|
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
|