mirror of
https://github.com/YunoHost-Apps/lutim_ynh.git
synced 2024-09-03 19:36:24 +02:00
199 lines
6.7 KiB
Bash
199 lines
6.7 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# 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"
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=2
|
|
|
|
# Fix always_encrypt as a boolean
|
|
if [ "${always_encrypt:-}" = "Yes" ]; then
|
|
ynh_app_setting_set --app=$app --key=always_encrypt --value=1
|
|
always_encrypt=1
|
|
elif [ "${always_encrypt:-}" = "No" ]; then
|
|
ynh_app_setting_set --app=$app --key=always_encrypt --value=0
|
|
always_encrypt=0
|
|
fi
|
|
|
|
# If overwrite_settings doesn't exist, create it
|
|
if [ -z "${overwrite_settings:-}" ]; then
|
|
overwrite_settings=1
|
|
ynh_app_setting_set --app=$app --key=overwrite_settings --value=$overwrite_settings
|
|
fi
|
|
|
|
# If overwrite_nginx doesn't exist, create it
|
|
if [ -z "${overwrite_nginx:-}" ]; then
|
|
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
|
|
fi
|
|
|
|
# If secret doesn't exist, create it
|
|
if [ -z "${secret:-}" ]; then
|
|
secret=$(grep "secrets *=>" "$install_dir/lutim.conf" | cut -d\' -f2)
|
|
ynh_app_setting_set --app=$app --key=secret --value=$secret
|
|
fi
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_script_progression --message="Upgrading source files..."
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$install_dir"
|
|
fi
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R $app:www-data "$install_dir"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
|
|
# 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
|
|
ynh_add_nginx_config
|
|
fi
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# SETUP LUTIM
|
|
#=================================================
|
|
ynh_script_progression --message="Reconfiguring $app..."
|
|
|
|
# Overwrite the settings config file only if it's allowed
|
|
if [ $overwrite_settings -eq 1 ]
|
|
then
|
|
workers="$(( $(nproc) * 2 ))"
|
|
ynh_add_config --template="../conf/lutim.conf.template" --destination="$install_dir/lutim.conf"
|
|
|
|
chmod 400 "$install_dir/lutim.conf"
|
|
chown $app:$app "$install_dir/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="$install_dir/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="$install_dir/lutim.conf"
|
|
fi
|
|
fi
|
|
if [ -n "$delay" ]; then
|
|
ynh_replace_string --match_string=".*default_delay *=>.*" --replace_string=" default_delay => $delay," --target_file="$install_dir/lutim.conf"
|
|
fi
|
|
fi
|
|
|
|
#=================================================
|
|
# 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"
|
|
|
|
#=================================================
|
|
# SETUP CRON
|
|
#=================================================
|
|
|
|
ynh_add_config --template="../conf/cron_lutim" --destination="/etc/cron.d/$app"
|
|
|
|
#=================================================
|
|
# UPDATE LUTIM WITH CARTON
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_script_progression --message="Upgrading $app with Carton..." --weight=4
|
|
pushd "$install_dir"
|
|
ynh_secure_remove --file="$install_dir/local"
|
|
carton install --without=mysql --without=htpasswd --without=test
|
|
popd
|
|
fi
|
|
|
|
#=================================================
|
|
# 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
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading logrotate configuration..."
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
ynh_use_logrotate --non-append
|
|
chown $app -R /var/log/$app
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
yunohost service add $app --log="$install_dir/log/production.log"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=4
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --line_match="Manager.*started" --log_path="/var/log/$app/production.log" --timeout="120"
|
|
|
|
#=================================================
|
|
# DEACTIVE MAINTENANCE MODE
|
|
#=================================================
|
|
|
|
ynh_maintenance_mode_OFF
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|