#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) domain=$(ynh_app_setting_get --app=$app --key=domain) port=$(ynh_app_setting_get --app=$app --key=port) path_url=$(ynh_app_setting_get --app=$app --key=path_url) client_max_body_size=$(ynh_app_setting_get --app=$app --key=client_max_body_size) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$(ynh_app_setting_get --app=$app --key=db_user) db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) datadir=$(ynh_app_setting_get --app=$app --key=datadir) registration_open=$(ynh_app_setting_get --app=$app --key=registration_open) registration_approval=$(ynh_app_setting_get --app=$app --key=registration_approval) registration_reason=$(ynh_app_setting_get --app=$app --key=registration_reason) media_image_max_size=$(ynh_app_setting_get --app=$app --key=media_image_max_size) media_video_max_size=$(ynh_app_setting_get --app=$app --key=media_video_max_size) media_description_min_chars=$(ynh_app_setting_get --app=$app --key=media_description_min_chars) media_description_max_chars=$(ynh_app_setting_get --app=$app --key=media_description_max_chars) media_remote_cache_days=$(ynh_app_setting_get --app=$app --key=media_remote_cache_days) statuses_max_chars=$(ynh_app_setting_get --app=$app --key=statuses_max_chars) statuses_cw_max_chars=$(ynh_app_setting_get --app=$app --key=statuses_cw_max_chars) statuses_poll_max_options=$(ynh_app_setting_get --app=$app --key=statuses_poll_max_options) statuses_poll_option_max_chars=$(ynh_app_setting_get --app=$app --key=statuses_poll_option_max_chars) statuses_media_max_files=$(ynh_app_setting_get --app=$app --key=statuses_media_max_files) #================================================= # CHECK VERSION #================================================= ### This helper will compare the version of the currently installed app and the version of the upstream package. ### $upgrade_type can have 2 different values ### - UPGRADE_APP if the upstream app version has changed ### - UPGRADE_PACKAGE if only the YunoHost package has changed ### ynh_check_app_version_changed will stop the upgrade if the app is up to date. ### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do. 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)..." # 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..." ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." # Upgrade from <0.2.1~ynh4: if [ -z "$client_max_body_size" ]; then client_max_body_size="50M" ynh_app_setting_set --app=$app --key=client_max_body_size --value=$client_max_body_size fi if [ -z "$client_max_body_size" ]; then media-image-max-size="2097152" ynh_app_setting_set --app=$app --key=media_image_max_size --value=$media_image_max_size fi if [ -z "$client_max_body_size" ]; then media-video-max-size="10485760" ynh_app_setting_set --app=$app --key=media_video_max_size --value=$media_video_max_size fi if [ -z "$client_max_body_size" ]; then media-description-min-chars="0" ynh_app_setting_set --app=$app --key=media_description_min_chars --value=$media_description_min_chars fi if [ -z "$client_max_body_size" ]; then media-description-max-chars="500" ynh_app_setting_set --app=$app --key=media_description_max_chars --value=$media_description_max_chars fi if [ -z "$client_max_body_size" ]; then media-remote-cache-days="30" ynh_app_setting_set --app=$app --key=media_remote_cache_days --value=$media_remote_cache_days fi if [ -z "$client_max_body_size" ]; then statuses-max-chars="5000" ynh_app_setting_set --app=$app --key=statuses_max_chars --value=$statuses_max_chars fi if [ -z "$client_max_body_size" ]; then statuses-cw-max-chars="100" ynh_app_setting_set --app=$app --key=statuses_cw_max_chars --value=$statuses_cw_max_chars fi if [ -z "$client_max_body_size" ]; then statuses-poll-max-options="6" ynh_app_setting_set --app=$app --key=statuses_poll_max_options --value=$statuses_poll_max_options fi if [ -z "$client_max_body_size" ]; then statuses-poll-option-max-chars="50" ynh_app_setting_set --app=$app --key=statuses_poll_option_max_chars --value=$statuses_poll_option_max_chars fi if [ -z "$client_max_body_size" ]; then statuses-media-max-files="6" ynh_app_setting_set --app=$app --key=statuses_media_max_files --value=$statuses_media_max_files 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 --home_dir="$final_path" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Upgrading source files..." architecture=$YNH_ARCH # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" --source_id=$architecture --keep="config.yaml" fi # FIXME: this should be managed by the core in the future # Here, as a packager, you may have to tweak the ownerhsip/permissions # such that the appropriate users (e.g. maybe www-data) can access # files in some cases. # But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder - # this will be treated as a security issue. chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Upgrading NGINX web server configuration..." # Create a dedicated NGINX config ynh_add_nginx_config #================================================= # UPGRADE DEPENDENCIES #================================================= ynh_script_progression --message="Upgrading dependencies..." ynh_install_app_dependencies $pkg_dependencies #================================================= # UPDATE A CONFIG FILE #================================================= ynh_script_progression --message="Updating a configuration file..." ### Same as during install ### ### The file will automatically be backed-up if it's found to be manually modified (because ### ynh_add_config keeps track of the file's checksum) ynh_add_config --template="config.yaml" --destination="$final_path/config.yaml" # FIXME: this should be handled by the core in the future # You may need to use chmod 600 instead of 400, # for example if the app is expected to be able to modify its own config chmod 400 "$final_path/config.yaml" chown $app:$app "$final_path/config.yaml" #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression --message="Upgrading systemd configuration..." # Create a dedicated systemd config ynh_add_systemd_config #================================================= # GENERIC FINALIZATION #================================================= # SETUP LOGROTATE #================================================= ynh_script_progression --message="Upgrading logrotate configuration..." # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add $app --description="Gotosocial server" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Upgrade of $app completed"