#!/bin/bash #================================================= # GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers # Load common variables for all scripts. source _variables #================================================= # LOAD SETTINGS #================================================= ynh_script_progression --message="Loading installation settings..." --weight=4 app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) is_public=$(ynh_app_setting_get --app=$app --key=is_public) 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) # Optional parameters from config-panel feature antiflood=$(ynh_app_setting_get --app=$app --key=antiflood) delay=$(ynh_app_setting_get --app=$app --key=delay) #================================================= # CHECK VERSION #================================================= upgrade_type=$(ynh_check_app_version_changed) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=2 # Fix is_public as a boolean if [ "$is_public" = "Yes" ]; then ynh_app_setting_set --app=$app --key=is_public --value=1 is_public=1 elif [ "$is_public" = "No" ]; then ynh_app_setting_set --app=$app --key=is_public --value=0 is_public=0 fi # if final_path isn't set, which can happens with old scripts, set final_path. if [ -z "$final_path" ]; then final_path=/var/www/$app ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi # 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 *=>" "$final_path/lutim.conf" | cut -d\' -f2) ynh_app_setting_set --app=$app --key=secret --value=$secret fi # Close opened port if yunohost firewall list | grep -q "\- $port$" then ynh_exec_quiet yunohost firewall disallow TCP $port fi #================================================= # 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 () { # Clean installation remaining that are not handle by the remove script. ynh_clean_check_starting # restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # CHECK THE PATH #================================================= # Normalize the URL path syntax path_url=$(ynh_normalize_url_path --path_url=$path_url) #================================================= # ACTIVATE MAINTENANCE MODE #================================================= ynh_script_progression --message="Activating maintenance mode..." --weight=2 ynh_maintenance_mode_ON #================================================= # STANDARD UPGRADE STEPS #================================================= # 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="$final_path" fi #================================================= # UPGRADE DEPENDENCIES #================================================= ynh_script_progression --message="Upgrading dependencies..." --weight=9 ynh_install_app_dependencies $app_depencencies #================================================= # 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 #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Making sure dedicated system user exists..." # Create a dedicated user (if not existing) ynh_system_user_create --username=$app #================================================= # SPECIFIC UPGRADE #================================================= # SETUP LUTIM #================================================= ynh_script_progression --message="Reconfigure Lutim" # Overwrite the settings config file only if it's allowed if [ $overwrite_settings -eq 1 ] then # 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" # 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" # 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 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 #================================================= # SETUP CRON #================================================= cp ../conf/cron_lutim /etc/cron.d/$app ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path/" --target_file=/etc/cron.d/$app #================================================= # UPDATE LUTIM WITH CARTON #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Upgrading Lutim with carton..." --weight=4 (cd $final_path carton install 2>&1 | tee -a "/var/log/$app/setup_carton.log") fi #================================================= # SECURING FILES AND DIRECTORIES #================================================= # Set permissions on app files chown -R $app: $final_path #================================================= # GENERIC FINALISATION #================================================= # SETUP LOGROTATE #================================================= ynh_script_progression --message="Upgrading logrotate configuration..." ynh_use_logrotate --non-append chown $app -R /var/log/$app #================================================= # SETUP SSOWAT #================================================= ynh_script_progression --message="Upgrading SSOwat configuration..." ynh_app_setting_set --app=$app --key=skipped_uris --value="/" if [ $is_public -eq 0 ] then # If the app is private, viewing images stays publicly accessible. # 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]/.*$" fi #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload #================================================= # START AND CHECK LUTIM BOOTING #================================================= ynh_script_progression --message="Restarting Lutim..." --weight=4 # Wait for lutim to be fully started ynh_systemd_action --action=restart --line_match="Manager.*started" --log_path="/var/log/$app/production.log" --timeout="120" #================================================= # DEACTIVE MAINTENANCE MODE #================================================= ynh_script_progression --message="Disabling maintenance mode..." --weight=7 ynh_maintenance_mode_OFF #================================================= # 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" # Build the changelog ynh_app_changelog || true echo "You can find a config file at $final_path/lutim.conf 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 ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=upgrade #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Upgrade of $app completed" --last