1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/castopod_ynh.git synced 2024-09-03 18:16:14 +02:00
castopod_ynh/scripts/upgrade
2024-07-13 23:47:18 +02:00

130 lines
4.7 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# 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 redis_db doesn't exist, create it
if [ -z "${redis_db:-}" ]; then
# Configure redis
redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
fi
#=================================================
# MOVE DATA TO __DATA_DIR__
#=================================================
if ynh_compare_current_package_version --comparison le --version "1.1.2~ynh2"; then
ynh_script_progression --message="Moving data..." --weight=3
mkdir -p $data_dir/media
cp -rf $install_dir/public/media/* $data_dir/media
chmod -R 750 $data_dir
chown -R $app:www-data $data_dir
ynh_secure_remove --file="$install_dir/public/media"
ynh_script_progression --message="Fixing migrations..." --weight=1
# this will fail is `cp-install` was not run on prev version - just ignore, DB schema is (re)generated later.
ynh_mysql_execute_as_root --database=$db_name --sql="UPDATE cp_migrations SET class='Media\\\\Database\\\\Migrations\\\\AddMedia', namespace='Media' where class='App\\\\Database\\\\Migrations\\\\AddMedia'" || true
elif ynh_compare_current_package_version --comparison lt --version "1.6.5~ynh2"; then
chown -R $app:www-data $data_dir
fi
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# 1.7.1~ynh2 accidently shipped 1.6.5, force upgrade on that version even if it's theoretically the same upstream release
if [ "$upgrade_type" == "UPGRADE_APP" ] || ynh_compare_current_package_version --comparison eq --version "1.7.1~ynh2"
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" --full_replace=1
fi
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...)
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1
# Create a dedicated PHP-FPM config
ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint
# Create a dedicated NGINX config
ynh_add_nginx_config
ynh_add_config --template="cron" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app"
chmod 644 "/etc/cron.d/$app"
#=================================================
# CONFIGURE CASTOPOD
#=================================================
ynh_script_progression --message="Configuring $app..." --weight=1
ynh_add_config --template=".env.example" --destination="$install_dir/.env"
chmod 600 $install_dir/.env
chown $app:www-data "$install_dir/.env"
#=================================================
# RUN MIGRATIONS
#=================================================
ynh_script_progression --message="Configuring $app database..." --weight=1
pushd $install_dir
ynh_exec_warn_less ynh_exec_as $app php${phpversion} spark cache:clear
ynh_exec_warn_less ynh_exec_as $app php${phpversion} spark castopod:database-update
popd
if ynh_compare_current_package_version --comparison le --version "1.6.5~ynh1"; then
# cf https://code.castopod.org/adaures/castopod/-/releases/v1.5.2
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < "../conf/sql/v1.5.2.sql"
fi
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last