#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # CHECK VERSION #================================================= upgrade_type=$(ynh_check_app_version_changed) #================================================= # STANDARD UPGRADE STEPS #================================================= # STOP SUPERVISOR SERVICE #================================================= ynh_script_progression --message="Stopping a supervisor service..." --weight=1 ynh_supervisor_action --service_name="${app}-horizon" --action="stop" --log_path="systemd" --line_match="stopped: ${app}-horizon" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # If fpm_footprint doesn't exist, create it if [ -z "${fpm_footprint:-}" ]; then fpm_footprint=low ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint fi # If fpm_free_footprint doesn't exist, create it if [ -z "${fpm_free_footprint:-}" ]; then fpm_free_footprint=0 ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint fi # If fpm_usage doesn't exist, create it if [ -z "${fpm_usage:-}" ]; then fpm_usage=low ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage fi # If app_key doesn't exist, retrieve it if [ -z "${app_key:-}" ]; then ynh_script_progression --message="Retrieving app_key..." app_key=$(grep -oP "APP_KEY=\Kbase64.*" "$install_dir/.env") ynh_app_setting_set --app="$app" --key=app_key --value="$app_key" fi if dpkg --compare-versions "0.9.0~ynh3" gt "$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version" || echo 1.0)" ; then ynh_script_progression --message="Ensuring upgrade compatibility to 0.9.0~ynh3..." ynh_script_progression --message="Configuring a systemd service..." ynh_add_systemd_config --service="${app}-horizon" --template=horizon.conf fi if dpkg --compare-versions "0.10.9~ynh2" gt "$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version" || echo 1.0)" ; then ynh_script_progression --message="Ensuring upgrade compatibility to 0.10.9~ynh2..." ynh_script_progression --message="Stopping and removing the systemd service..." ynh_remove_systemd_config --service="${app}-horizon" ynh_script_progression --message="Creating log file..." mkdir -p "/var/log/$app/" touch "/var/log/$app/${app}-horizon.log" chown -R $app: "/var/log/$app/" ynh_script_progression --message="Configuring a supervisor service..." ynh_add_supervisor_config --service="${app}-horizon" --template=horizon.conf ynh_script_progression --message="Starting a supervisor service..." ynh_supervisor_action --service_name="${app}-horizon" --action="start" --log_path="systemd" --line_match="success: ${app}-horizon" fi if dpkg --compare-versions "0.10.9~ynh3" gt "$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version" || echo 1.0)" ; then ynh_script_progression --message="Ensuring upgrade compatibility to 0.10.9~ynh3..." if ynh_exec_warn_less yunohost service status ${app}-horizon >/dev/null then ynh_script_progression --message="Removing ${app}-horizon service..." yunohost service remove "${app}-horizon" fi ynh_script_progression --message="Integrating service in YunoHost..." yunohost service add "supervisor" --description="Supervisor daemon for $app" --log="/var/log/$app/${app}-horizon.log" fi # Fix old email configs if ynh_compare_current_package_version --comparison lt --version "0.11.8~ynh5" ; then ynh_replace_special_string --match_string="MAIL_DRIVER=[^\\n]*" --replace_string="MAIL_DRIVER=sendmail" --target_file="$install_dir/.env" # two \\ because it's in a "" ynh_replace_special_string --match_string="MAIL_HOST=[^\\n]*" --replace_string="MAIL_HOST=127.0.0.1" --target_file="$install_dir/.env" # two \\ because it's in a "" ynh_replace_special_string --match_string="MAIL_USERNAME=[^\\n]*" --replace_string="MAIL_USERNAME=$app" --target_file="$install_dir/.env" # two \\ because it's in a "" ynh_replace_special_string --match_string="MAIL_PASSWORD=[^\\n]*" --replace_string="MAIL_PASSWORD=$mail_pwd" --target_file="$install_dir/.env" # two \\ because it's in a "" ynh_replace_special_string --match_string="MAIL_FROM_ADDRESS=pixelfed" --replace_string=`MAIL_FROM_ADDRESS="$app"` --target_file="$install_dir/.env" fi #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Upgrading source files..." --weight=1 # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir" --keep=".env" fi chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" # Pixelfed app should be able to edit its settings from the admin panel chmod 600 "$install_dir"/.env #================================================= # PATCHING SOURCE #================================================= ynh_script_progression --message="Patching source files..." --weight=1 # Prevent privilege escalation by injecting commands in an email name # This described in more detail on the manpage https://www.postfix.org/sendmail.1.html under security ynh_replace_string --match_string="'/usr/sbin/sendmail -bs'" --replace_string="'/usr/sbin/sendmail -bs -- '" --target_file=$install_dir/config/mail.php #================================================= # PHP-FPM CONFIGURATION #================================================= ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1 # Create a dedicated PHP-FPM config ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint --group=www-data #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config #================================================= # SPECIFIC UPGRADE #================================================= # UPDATE COMPOSER DEPENDENCIES #================================================= ynh_script_progression --message="Updating composer..." --weight=1 ynh_exec_warn_less ynh_composer_exec --workdir="$install_dir" --commands="self-update --2" ynh_exec_warn_less ynh_composer_exec --workdir="$install_dir" --commands="update" #================================================= # PATCH PERMISSIONS for v0.11.5 versions and higher #================================================= ynh_script_progression --message="Patching permissions (for version 0.11.5 and newer)..." --weight=1 # Default configuration doesn't work ynh_replace_string --match_string="'private' => 0700," --replace_string="'private' => 0750," --target_file=$install_dir/config/filesystems.php # Repair permissions for files created after v0.11.5 and before this patch if [ -d "$install_dir/public/storage/m/_v2/" ]; then chmod 750 -R "$install_dir/public/storage/m/_v2/"* # all files subdirectories (picture folders) should be readable and executable. But if there is no picture, there is no /*/* chmod 770 "$install_dir/public/storage/m/_v2/"* # users folders should be 770 chmod 770 "$install_dir/public/storage/m/_v2/" # this should be 770 chown -R :www-data "$install_dir/public/storage/m/_v2/" # Fix the mess following packaging v2 upgrade - and make sure proper group owner is set. fi #================================================= # DEPLOYMENT #================================================= ynh_script_progression --message="Deploying..." pushd "$install_dir" php$phpversion artisan horizon:install php$phpversion artisan horizon:publish php$phpversion artisan passport:keys --force php$phpversion artisan config:clear php$phpversion artisan config:cache php$phpversion artisan route:clear php$phpversion artisan route:cache php$phpversion artisan view:clear php$phpversion artisan view:cache php$phpversion artisan storage:link php$phpversion artisan migrate --force php$phpversion artisan update php$phpversion artisan horizon:purge php$phpversion artisan import:cities 2>/dev/null php$phpversion artisan instance:actor php$phpversion artisan passport:client --personal <<< "\\n" popd #================================================= # CREATE LOG FILE #================================================= ynh_script_progression --message="Creating log file..." --weight=1 mkdir -p "/var/log/$app/" touch "/var/log/$app/${app}-horizon.log" chown -R $app: "/var/log/$app/" chmod -R 600 "/var/log/$app/" #================================================= # UPGRADE THE CRON FILE #================================================= ynh_script_progression --message="Upgrading cron file..." --weight=1 ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" #================================================= # SETUP SUPERVISOR #================================================= ynh_script_progression --message="Upgrading supervisor configuration..." --weight=1 # Create a dedicated supervisor config ynh_add_supervisor_config --service="${app}-horizon" --template=horizon.conf #================================================= # GENERIC FINALIZATION #================================================= # SETUP LOGROTATE #================================================= ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 # 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..." --weight=1 yunohost service add "supervisor" --description="Supervisor daemon for $app" --log="/var/log/$app/${app}-horizon.log" #================================================= # START SUPERVISOR SERVICE #================================================= ynh_script_progression --message="Starting a supervisor service..." --weight=1 ynh_supervisor_action --service_name="${app}-horizon" --action="start" --log_path="systemd" --line_match="success: ${app}-horizon" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Upgrade of $app completed" --last