#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source ynh_install_go source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) admin=$(ynh_app_setting_get --app=$app --key=admin) password=$(ynh_app_setting_get --app=$app --key=password) final_path=$(ynh_app_setting_get --app=$app --key=final_path) group_name=$(ynh_app_setting_get --app=$app --key=group_name) group_description=$(ynh_app_setting_get --app=$app --key=group_description) port=$(ynh_app_setting_get --app=$app --key=port) ldap_port=$(ynh_app_setting_get --app=$app --key=ldap_port) key=$(ynh_app_setting_get --app=$app --key=key) turn_port=$(ynh_app_setting_get --app=$app --key=turn_port) datadir=$(ynh_app_setting_get --app=$app --key=datadir) if ynh_compare_current_package_version --comparison le --version 0.3.5~ynh3 then ynh_die --message="Please, you need to remove the app and reinstall it" fi #================================================= # CHECK VERSION #================================================= ynh_script_progression --message="Checking version..." --weight=1 upgrade_type=$(ynh_check_app_version_changed) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { # Restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= ynh_script_progression --message="Stopping a systemd service..." --weight=3 ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" ynh_systemd_action --service_name=${app}_ldap --action="stop" --log_path="systemd" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # If open, close direct access to $port in firewall if yunohost firewall list | grep -q "\- $port$" then ynh_exec_warn_less yunohost firewall disallow TCP $port fi # If final_path doesn't exist, create it if [ -z "$final_path" ]; then final_path=/var/www/$app mkdir -p $final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi # If ldap_port doesn't exist, create it if [ -z "$ldap_port" ]; then ldap_port=$(ynh_find_port --port=$(($port + 1))) ynh_app_setting_set --app=$app --key=port --value=$ldap_port fi # Cleaning legacy permissions if ynh_legacy_permissions_exists; then ynh_legacy_permissions_delete_all ynh_app_setting_delete --app=$app --key=is_public fi # We remove the old admin/password file if present if [ -f "$final_path/data/passwd" ] ; then ynh_secure_remove --file="$final_path/data/passwd" fi # For version 0.6~ynh1 and before if [[ ! -d "$final_path/live" ]] then tempdir="$(mktemp -d)" mv $final_path $tempdir mkdir -p "$final_path/live" mv $tempdir/$app/galene "$final_path/live/" mv $tempdir/$app/data/ "$final_path/live/" mv $tempdir/$app/static/ "$final_path/live/" ynh_secure_remove --file="$tempdir" fi #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # Create a dedicated user (if not existing) ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Upgrading source files..." --weight=2 ynh_setup_source --dest_dir="$final_path/build" ynh_setup_source --dest_dir="$final_path/build_ldap" --source_id="ldap" mkdir -p "$final_path/live/data" mkdir -p "$final_path/live_ldap/data" ynh_secure_remove --file="$final_path/live/static/" cp -r "$final_path/build/static/" "$final_path/live/" ynh_replace_string --match_string="