2015-03-16 21:10:39 +01:00
#!/bin/bash
2017-03-19 19:16:10 +01:00
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2016-06-15 23:56:45 +02:00
2017-03-21 00:44:14 +01:00
source _common.sh
2016-12-14 16:10:00 +01:00
source /usr/share/yunohost/helpers
2017-12-05 19:36:40 +01:00
# Load common variables for all scripts.
source _variables
2016-12-14 16:10:00 +01:00
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)
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
2020-01-29 15:24:28 +01:00
skipped_uris=$(ynh_app_setting_get --app=$app --key=skipped_uris)
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
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-01-29 15:24:28 +01:00
if [ ! -z "$skipped_uris" ]; then
ynh_app_setting_delete --app=$app --key=skipped_uris
2017-03-19 19:16:10 +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
2016-03-31 23:26:35 +02:00
final_path=/var/www/$app
2020-01-02 18:40:15 +01:00
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-01-02 18:40:15 +01:00
ynh_app_setting_set --app=$app --key=always_encrypt --value=1
2017-03-19 19:16:10 +01:00
always_encrypt=1
elif [ "$always_encrypt" = "No" ]; then
2020-01-02 18:40:15 +01:00
ynh_app_setting_set --app=$app --key=always_encrypt --value=0
2017-03-19 19:16:10 +01:00
always_encrypt=0
fi
2018-09-30 11:52:12 +02:00
# If overwrite_settings doesn't exist, create it
if [ -z "$overwrite_settings" ]; then
overwrite_settings=1
2020-01-02 18:40:15 +01:00
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
overwrite_nginx=1
2020-01-02 18:40:15 +01:00
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
overwrite_systemd=1
2020-01-02 18:40:15 +01:00
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
secret=$(grep "secrets *=>" "$final_path/lutim.conf" | cut -d\' -f2)
2020-01-02 18:40:15 +01:00
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
ynh_exec_quiet yunohost firewall disallow TCP $port
fi
2017-03-19 19:16:10 +01:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=15
2017-03-19 19:16:10 +01:00
2017-09-05 00:25:58 +02:00
# Backup the current version of the app
ynh_backup_before_upgrade
2017-03-19 19:16:10 +01:00
ynh_clean_setup () {
2019-01-18 19:56:43 +01:00
# Clean installation remaining that are not handle by the remove script.
2017-12-16 23:22:54 +01:00
ynh_clean_check_starting
2017-09-05 00:25:58 +02:00
# restore it if the upgrade fails
ynh_restore_upgradebackup
2017-03-19 19:16:10 +01:00
}
2017-09-05 00:25:58 +02:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2016-03-31 23:26:35 +02:00
2017-03-19 19:16:10 +01:00
#=================================================
# CHECK THE PATH
#=================================================
2015-03-27 23:26:10 +01:00
2019-01-18 19:56:43 +01:00
# Normalize the URL path syntax
2020-01-02 18:40:15 +01:00
path_url=$(ynh_normalize_url_path --path_url=$path_url)
2017-03-19 19:16:10 +01:00
2018-05-20 20:55:15 +02:00
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Activating maintenance mode..." --weight=2
2018-05-20 20:55:15 +02:00
ynh_maintenance_mode_ON
2017-03-19 19:16:10 +01:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2019-01-13 19:10:28 +01:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Upgrading source files..."
2019-01-18 19:56:43 +01:00
# Download, check integrity, uncompress and patch the source from app.src
2020-01-02 18:40:15 +01:00
ynh_setup_source --dest_dir="$final_path"
2019-01-13 19:10:28 +01:00
fi
2017-03-19 19:16:10 +01:00
2017-12-05 19:36:40 +01:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Upgrading dependencies..." --weight=9
2017-12-05 19:36:40 +01:00
2019-01-13 19:10:28 +01:00
ynh_install_app_dependencies $app_depencencies
2017-12-05 19:36:40 +01: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
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=2
2018-09-30 11:52:12 +02:00
ynh_add_nginx_config
fi
2015-03-26 13:07:01 +01:00
2017-03-19 19:16:10 +01:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Making sure dedicated system user exists..."
2017-03-19 19:16:10 +01:00
2019-01-18 19:56:43 +01:00
# Create a dedicated user (if not existing)
2020-01-02 18:40:15 +01:00
ynh_system_user_create --username=$app
2017-03-19 19:16:10 +01:00
#=================================================
# SPECIFIC UPGRADE
#=================================================
# SETUP LUTIM
#=================================================
2019-01-30 16:19:40 +01:00
ynh_script_progression --message="Reconfigure Lutim"
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
2019-01-18 19:56:43 +01:00
# Configure Lutim
# Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
2020-01-02 18:40:15 +01:00
ynh_backup_if_checksum_is_different --file="$final_path/lutim.conf"
2018-09-30 11:52:12 +02:00
cp ../conf/lutim.conf.template "$final_path/lutim.conf"
2020-01-02 18:40:15 +01:00
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"
2019-01-18 19:56:43 +01:00
# Recalculate and store the checksum of the file for the next upgrade.
2020-01-02 18:40:15 +01:00
ynh_store_file_checksum --file="$final_path/lutim.conf"
2018-09-30 11:52:12 +02:00
# Optional parameters from config-panel feature
if [ -n "$antiflood" ]; then
2020-01-02 18:40:15 +01:00
ynh_replace_string --match_string=".*anti_flood_delay *=>.*" --replace_string=" anti_flood_delay => $antiflood," --target_file="$final_path/lutim.conf"
2018-09-30 11:52:12 +02:00
# Disable anti_flood_delay if the delay is 0
if [ $antiflood = 0 ]; then
2020-01-02 18:40:15 +01:00
ynh_replace_string --match_string="\(anti_flood_delay *=>.*\)" --replace_string="#\1" --target_file="$final_path/lutim.conf"
2018-09-30 11:52:12 +02:00
fi
fi
if [ -n "$delay" ]; then
2020-01-02 18:40:15 +01:00
ynh_replace_string --match_string=".*default_delay *=>.*" --replace_string=" default_delay => $delay," --target_file="$final_path/lutim.conf"
2018-09-30 11:52:12 +02:00
fi
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 SYSTEMD
#=================================================
2018-09-30 11:52:12 +02:00
# Overwrite the systemd configuration only if it's allowed
if [ $overwrite_systemd -eq 1 ]
then
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Upgrading systemd configuration..." --weight=2
2018-09-30 11:52:12 +02:00
ynh_add_systemd_config
fi
2017-03-19 19:16:10 +01:00
#=================================================
# SETUP CRON
#=================================================
2015-03-16 21:10:39 +01:00
2017-09-05 00:25:58 +02:00
cp ../conf/cron_lutim /etc/cron.d/$app
2020-01-02 18:40:15 +01:00
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path/" --target_file=/etc/cron.d/$app
2020-01-02 18:43:40 +01:00
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file=/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
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Upgrading Lutim with carton..." --weight=4
2018-07-13 17:33:54 +02:00
(cd $final_path
carton install 2>&1 | tee -a "/var/log/$app/setup_carton.log")
fi
2017-03-19 19:16:10 +01:00
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
2019-01-18 19:56:43 +01:00
# Set permissions on app files
2017-09-05 00:25:58 +02:00
chown -R $app: $final_path
2017-03-19 19:16:10 +01:00
#=================================================
# GENERIC FINALISATION
#=================================================
# 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
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
#=================================================
# SETUP SSOWAT
#=================================================
2020-01-29 15:24:28 +01:00
ynh_script_progression --message="Upgrading permission..."
2015-08-19 21:33:40 +02:00
2020-02-11 09:59:59 +01:00
if ! ynh_permission_exists --permission="upload images"
then
if [ -z $(ynh_app_setting_get --app=$app --key=protected_regex) ] # Everyone can upload image
then
ynh_permission_create --permission="upload images" --allowed="visitors"
else # Only user with a yunohost account can upload an image
ynh_permission_create --permission="upload images" --allowed="all_users"
fi
fi
2015-03-16 21:10:39 +01:00
2017-03-19 19:16:10 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Reloading nginx web server..."
2015-03-26 13:07:01 +01:00
2020-01-02 18:40:15 +01:00
ynh_systemd_action --service_name=nginx --action=reload
2017-05-24 16:48:26 +02:00
#=================================================
# START AND CHECK LUTIM BOOTING
#=================================================
2020-01-02 18:40:15 +01:00
ynh_script_progression --message="Restarting Lutim..." --weight=4
2017-05-24 16:48:26 +02:00
2019-01-18 19:56:43 +01:00
# Wait for lutim to be fully started
2019-01-13 19:10:28 +01:00
ynh_systemd_action --action=restart --line_match="Manager.*started" --log_path="/var/log/$app/production.log" --timeout="120"
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