2015-05-31 13:46:25 +02:00
|
|
|
#!/bin/bash
|
2018-03-13 21:49:11 +01:00
|
|
|
|
|
|
|
#=================================================
|
2021-07-12 12:16:32 +02:00
|
|
|
# GENERIC START
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2017-02-06 23:40:55 +01:00
|
|
|
source _common.sh
|
2021-07-12 12:16:32 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2015-05-31 13:46:25 +02:00
|
|
|
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2021-07-12 12:11:43 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2017-02-06 23:40:55 +01:00
|
|
|
|
2021-07-12 12:11:43 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
2022-06-15 23:45:27 +02:00
|
|
|
db_user=$db_name
|
2021-07-12 12:11:43 +02:00
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
2022-06-15 23:45:27 +02:00
|
|
|
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
2021-07-12 12:11:43 +02:00
|
|
|
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
2022-06-15 23:45:27 +02:00
|
|
|
prefix=$(ynh_app_setting_get --app=$app --key=prefix)
|
|
|
|
is_admin_public=$(ynh_app_setting_get --app=$app --key=is_admin_public)
|
2018-03-13 21:49:11 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
|
2021-07-12 12:11:43 +02:00
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
2018-03-13 21:49:11 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2021-07-12 12:11:43 +02:00
|
|
|
ynh_script_progression --message="Backing up $app before upgrading (may take a while)..." --weight=7
|
2018-03-13 21:49:11 +01:00
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
2022-06-15 23:45:27 +02:00
|
|
|
# Restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
2018-03-13 21:49:11 +01:00
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2022-06-15 23:45:27 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
2021-07-12 12:11:43 +02:00
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
2021-07-12 12:16:32 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
2021-07-12 12:11:43 +02:00
|
|
|
|
|
|
|
# If db_name doesn't exist, create it
|
2021-07-12 14:06:32 +02:00
|
|
|
if [ -z "$db_name" ]; then
|
2022-06-15 23:45:27 +02:00
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
2021-07-12 14:06:32 +02:00
|
|
|
fi
|
2021-07-12 12:11:43 +02:00
|
|
|
|
|
|
|
# If final_path doesn't exist, create it
|
2021-07-12 14:06:32 +02:00
|
|
|
if [ -z "$final_path" ]; then
|
2022-06-15 23:45:27 +02:00
|
|
|
final_path=/var/www/$app
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2021-07-12 14:06:32 +02:00
|
|
|
fi
|
2021-07-12 12:11:43 +02:00
|
|
|
|
2022-06-16 00:33:32 +02:00
|
|
|
# If prefix doesn't exist, create it
|
|
|
|
if [ -z "$prefix" ]; then
|
|
|
|
prefix="lime_"
|
|
|
|
ynh_app_setting_set --app=$app --key=prefix --value=$prefix
|
|
|
|
fi
|
|
|
|
|
2022-01-14 01:29:27 +01:00
|
|
|
# If datadir doesn't exist, create it
|
|
|
|
if [ -z "$datadir" ]; then
|
2022-06-15 23:45:27 +02:00
|
|
|
datadir=/home/yunohost.app/$app/upload
|
|
|
|
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
|
|
|
|
mkdir -p $datadir
|
|
|
|
# Remove upload if empty
|
|
|
|
rmdir $datadir 2> /dev/null && mv "$final_path/upload" $datadir || true
|
|
|
|
chown -R $app:www-data "$datadir"
|
|
|
|
chmod -R o-rwx "$datadir"
|
2022-06-16 00:33:32 +02:00
|
|
|
ln -s $datadir/upload $final_path/upload
|
2022-01-14 01:29:27 +01:00
|
|
|
fi
|
|
|
|
|
2021-07-12 12:11:43 +02:00
|
|
|
# Cleaning legacy permissions
|
|
|
|
if ynh_legacy_permissions_exists; then
|
2022-06-15 23:45:27 +02:00
|
|
|
ynh_legacy_permissions_delete_all
|
2018-03-13 21:49:11 +01:00
|
|
|
|
2022-06-15 23:45:27 +02:00
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
2021-07-12 12:11:43 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if ! ynh_permission_exists --permission="admin"; then
|
2022-06-15 23:45:27 +02:00
|
|
|
# Create the required permissions
|
|
|
|
if [ $is_admin_public -eq 1 ]
|
|
|
|
then
|
|
|
|
allowed_groups="visitors $admin"
|
|
|
|
else
|
|
|
|
allowed_groups="$admin"
|
|
|
|
fi
|
|
|
|
ynh_permission_create --permission="admin" --url="/admin" --allowed=$allowed_groups --show_tile="true"
|
|
|
|
|
2021-07-12 12:11:43 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Create a permission if needed
|
|
|
|
if ! ynh_permission_exists --permission="api"; then
|
2022-06-15 23:45:27 +02:00
|
|
|
ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true"
|
2021-07-12 12:11:43 +02:00
|
|
|
fi
|
2018-03-13 21:49:11 +01:00
|
|
|
|
2021-07-12 12:39:21 +02:00
|
|
|
#=================================================
|
|
|
|
# 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"
|
|
|
|
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
2021-07-12 13:29:21 +02:00
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
2022-06-15 23:45:27 +02:00
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=1
|
2018-03-13 21:49:11 +01:00
|
|
|
|
2022-06-15 23:45:27 +02:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2022-08-30 21:15:03 +02:00
|
|
|
ynh_setup_source --dest_dir="$final_path" --keep="plugins/ application/config/config.php"
|
2021-07-12 13:29:21 +02:00
|
|
|
fi
|
2018-03-14 03:32:46 +01:00
|
|
|
|
2021-07-12 13:10:03 +02:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
2022-01-14 01:29:27 +01:00
|
|
|
chmod 750 "$final_path/tmp"
|
|
|
|
chmod 750 "$final_path/application/config/"
|
|
|
|
chown -R $app:www-data "$datadir"
|
|
|
|
chmod 750 $datadir
|
2022-06-16 00:33:32 +02:00
|
|
|
ln -s $datadir/upload $final_path/upload 2> /dev/null || true
|
2021-07-12 13:10:03 +02:00
|
|
|
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
2021-07-12 12:39:21 +02:00
|
|
|
# UPGRADE DEPENDENCIES
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
2021-07-12 12:44:16 +02:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=1
|
2018-03-13 21:49:11 +01:00
|
|
|
|
2021-07-12 12:39:21 +02:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2015-06-01 00:00:38 +02:00
|
|
|
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2021-07-12 12:11:43 +02:00
|
|
|
ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1
|
2018-03-13 21:49:11 +01:00
|
|
|
|
2021-07-12 12:11:43 +02:00
|
|
|
# Create a dedicated PHP-FPM config
|
|
|
|
ynh_add_fpm_config
|
2018-03-13 21:49:11 +01:00
|
|
|
|
2022-01-14 02:52:48 +01:00
|
|
|
#=================================================
|
2022-06-15 23:45:27 +02:00
|
|
|
# NGINX CONFIGURATION
|
2022-01-14 02:52:48 +01:00
|
|
|
#=================================================
|
2022-06-15 23:45:27 +02:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
|
|
|
# UPDATE A CONFIG FILE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Updating a configuration file..." --weight=1
|
2022-01-14 02:52:48 +01:00
|
|
|
|
|
|
|
ynh_add_config --template="../conf/config.php" --destination="$final_path/application/config/config.php"
|
|
|
|
|
2022-06-15 23:45:27 +02:00
|
|
|
chmod 400 "$final_path/application/config/config.php"
|
|
|
|
chown $app:$app "$final_path/application/config/config.php"
|
|
|
|
|
2018-03-13 21:49:11 +01:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE DB
|
|
|
|
#=================================================
|
2022-06-15 23:45:27 +02:00
|
|
|
ynh_script_progression --message="Upgrading DB..."
|
2015-06-01 00:00:38 +02:00
|
|
|
|
2017-02-06 23:40:55 +01:00
|
|
|
# Migrate DB
|
2022-06-16 00:33:32 +02:00
|
|
|
ynh_exec_as "$app" php$phpversion $final_path/application/commands/console.php updatedb
|
2021-07-12 12:11:43 +02:00
|
|
|
|
2022-06-15 23:45:27 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
2021-07-12 12:11:43 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2021-07-12 12:16:32 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
2021-07-12 12:11:43 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2021-07-12 12:16:32 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|