mirror of
https://github.com/YunoHost-Apps/pixelfed_ynh.git
synced 2024-09-03 20:06:04 +02:00
273 lines
10 KiB
Bash
273 lines
10 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source ynh_redis
|
|
source ynh_supervisor
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading 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)
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
db_user=$db_name
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
|
app_key=$(ynh_app_setting_get --app=$app --key=app_key)
|
|
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
|
|
|
|
#=================================================
|
|
# 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 () {
|
|
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
|
|
|
|
#=================================================
|
|
# 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
|
|
|
|
ynh_app_setting_delete --app=$app --key=fpm_footprint
|
|
ynh_app_setting_delete --app=$app --key=fpm_usage
|
|
|
|
# If redis_db doesn't exist, create it
|
|
if [ -z "$redis_db" ]; then
|
|
redis_db=$(ynh_redis_get_free_db)
|
|
ynh_app_setting_set --app=$app --key=redis_db --value=$redis_db
|
|
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.*" "$final_path/.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="Installing dependencies..."
|
|
ynh_install_app_dependencies "$pkg_dependencies"
|
|
|
|
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..."
|
|
phpversion=$YNH_PHP_VERSION
|
|
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
|
|
|
|
# Cleaning legacy permissions
|
|
if ynh_legacy_permissions_exists; then
|
|
ynh_legacy_permissions_delete_all
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
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
|
|
#=================================================
|
|
|
|
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="$final_path" --keep=".env"
|
|
fi
|
|
|
|
chmod 750 "$final_path"
|
|
chmod -R o-rwx "$final_path"
|
|
chown -R $app:www-data "$final_path"
|
|
# Pixelfed app should be able to edit its settings from the admin panel
|
|
chmod 600 "$final_path"/.env
|
|
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=1
|
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
#=================================================
|
|
# PHP-FPM CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1
|
|
|
|
# Create a dedicated PHP-FPM config
|
|
ynh_add_fpm_config
|
|
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
|
|
|
#=================================================
|
|
# 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 dependencies..." --weight=1
|
|
|
|
ynh_exec_warn_less ynh_composer_exec --workdir="$final_path" --commands="update"
|
|
|
|
#=================================================
|
|
# DEPLOYMENT
|
|
#=================================================
|
|
ynh_script_progression --message="Deploying..."
|
|
|
|
pushd "$final_path"
|
|
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/"
|
|
|
|
#=================================================
|
|
# 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"
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|