1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/emailpoubelle_ynh.git synced 2024-09-03 18:26:29 +02:00
emailpoubelle_ynh/scripts/upgrade

171 lines
5.6 KiB
Text
Raw Normal View History

2018-11-18 16:00:35 +01:00
#!/bin/bash
2018-11-24 11:27:04 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2022-06-08 03:24:51 +02:00
2018-11-24 11:27:04 +01:00
source _common.sh
source /usr/share/yunohost/helpers
2018-11-24 11:27:04 +01:00
#=================================================
# LOAD SETTINGS
#=================================================
2020-11-01 16:49:03 +01:00
ynh_script_progression --message="Loading installation settings..."
2022-06-08 03:24:51 +02:00
2018-11-24 11:27:04 +01:00
app=$YNH_APP_INSTANCE_NAME
2022-06-08 03:24:51 +02:00
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)
db_user=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
2018-11-24 11:27:04 +01:00
2019-05-20 23:54:52 +02:00
#=================================================
# CHECK VERSION
#=================================================
2022-06-08 03:24:51 +02:00
ynh_script_progression --message="Checking version..."
2019-05-20 23:54:52 +02:00
upgrade_type=$(ynh_check_app_version_changed)
2022-06-08 03:24:51 +02:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# 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
2019-05-20 23:54:52 +02:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2020-11-01 16:49:03 +01:00
ynh_script_progression --message="Ensuring downward compatibility..."
2022-06-08 03:24:51 +02:00
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
2019-05-20 23:54:52 +02:00
# If db_name doesn't exist, create it
if [ -z "$db_name" ]; then
db_name=$(ynh_sanitize_dbid --db_name=$app)
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
fi
# If final_path doesn't exist, create it
if [ -z "$final_path" ]; then
final_path=/var/www/$app
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi
2022-06-08 03:24:51 +02:00
if [ -z $db_pwd ]; then
#c'est moche mais ça fera bien l'affaire - en deux lignes sinon pb en fonction du type de shell
t=$(cat /var/www/$app/conf.php | grep DBPASS)
db_pwd=${t:26:24}
ynh_app_setting_set --app=$app --key=mysqlpwd --value=$db_pwd
fi
#=================================================
2022-06-08 03:24:51 +02:00
# CREATE DEDICATED USER
#=================================================
2022-06-08 03:24:51 +02:00
ynh_script_progression --message="Making sure dedicated system user exists..."
2022-06-08 03:24:51 +02:00
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
2022-06-08 03:24:51 +02:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2019-05-20 23:54:52 +02:00
#=================================================
2022-06-08 03:24:51 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..."
2019-05-20 23:54:52 +02:00
2022-06-08 03:24:51 +02:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path" --keep="conf.php"
ynh_add_config --template="../conf/index_source.php" --destination="$final_path/www/index.php"
2022-06-10 20:52:48 +02:00
ynh_secure_remove --file="$final_path/www/admin.php"
2022-06-08 03:24:51 +02:00
2022-06-10 20:52:48 +02:00
test -e $final_path/www/lib
2022-06-08 03:24:51 +02:00
if [[ ! $? -eq 0 ]]; then
2022-06-10 20:52:48 +02:00
ln -s $final_path/lib $final_path/www/lib
2022-06-08 03:24:51 +02:00
fi
fi
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
2019-05-20 23:54:52 +02:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2020-11-01 16:49:03 +01:00
ynh_script_progression --message="Upgrading dependencies..."
2022-06-08 03:24:51 +02:00
2019-03-05 22:43:49 +01:00
ynh_install_app_dependencies $pkg_dependencies
2019-05-20 23:54:52 +02:00
#=================================================
2022-06-08 03:24:51 +02:00
# PHP-FPM CONFIGURATION
2019-05-20 23:54:52 +02:00
#=================================================
2022-06-08 03:24:51 +02:00
ynh_script_progression --message="Upgrading PHP-FPM configuration..."
2019-05-20 23:54:52 +02:00
2022-06-08 03:24:51 +02:00
# Create a dedicated PHP-FPM config
ynh_add_fpm_config
2018-11-25 16:19:51 +01:00
2019-03-05 22:43:49 +01:00
#=================================================
2022-06-08 03:24:51 +02:00
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..."
2019-05-20 23:54:52 +02:00
2022-06-08 03:24:51 +02:00
# Create a dedicated NGINX config
ynh_add_nginx_config
2019-05-20 23:54:52 +02:00
2022-06-08 03:24:51 +02:00
#=================================================
# SPECIFIC UPGRADE
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
ynh_add_config --template="../conf/conf-dist.php" --destination="$final_path/conf.php"
chmod 400 "$final_path/conf.php"
chown $app:$app "$final_path/conf.php"
2018-12-01 11:49:41 +01:00
2019-05-22 12:05:43 +02:00
cp -R ../sources/hooks/conf_regen/98-postfix_emailpoubelle /usr/share/yunohost/hooks/conf_regen/
2019-05-22 12:21:06 +02:00
mv /etc/postfix/main.cf /etc/postfix/main.cf.emailpoubelle.bak
2020-11-01 16:49:03 +01:00
yunohost tools regen-conf postfix -f
2022-06-08 03:24:51 +02:00
ynh_systemd_action --service_name=postfix --action=reload
2019-05-20 23:54:52 +02:00
2022-06-08 03:24:51 +02:00
# Adding cronjob for removing expired email addresses
ynh_add_config --template="../conf/emailpoubelle.cron" --destination="/etc/cron.d/$app"
2020-02-23 16:06:48 +01:00
chown root:root /etc/cron.d/$app
2022-06-08 03:24:51 +02:00
chmod 644 /etc/cron.d/$app
2018-11-18 16:00:35 +01:00
#=================================================
2022-06-08 03:24:51 +02:00
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
2022-06-08 03:24:51 +02:00
ynh_script_progression --message="Reloading NGINX web server..."
2020-11-01 16:49:03 +01:00
2019-05-20 23:54:52 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2020-11-01 16:49:03 +01:00
2022-06-08 03:24:51 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2020-11-01 16:49:03 +01:00
2022-06-08 03:24:51 +02:00
ynh_script_progression --message="Upgrade of $app completed"