mirror of
https://github.com/YunoHost-Apps/pixelfed_ynh.git
synced 2024-09-03 20:06:04 +02:00
176 lines
7.4 KiB
Bash
176 lines
7.4 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Stopping $app's systemd service..." --weight=1
|
|
|
|
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..." --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.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
|
|
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
|
|
#=================================================
|
|
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"
|
|
|
|
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
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
mkdir -p "/var/log/$app/"
|
|
touch "/var/log/$app/${app}-horizon.log"
|
|
chown -R $app: "/var/log/$app/"
|
|
chmod -R 600 "/var/log/$app/"
|
|
|
|
ynh_add_config --template="cron" --destination="/etc/cron.d/$app"
|
|
|
|
ynh_add_systemd_config
|
|
|
|
ynh_use_logrotate --non-append
|
|
|
|
yunohost service add "$app" --description="Federated Image Sharing" --log="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# 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
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
|
|
|
|
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|