1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/wordpress_ynh.git synced 2024-09-03 20:36:10 +02:00
wordpress_ynh/scripts/upgrade
2017-03-19 18:41:21 +01:00

164 lines
5.5 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source .fonctions
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
admin_wordpress=$(ynh_app_setting_get $app admin)
language=$(ynh_app_setting_get $app language)
is_public=$(ynh_app_setting_get $app is_public)
multisite=$(ynh_app_setting_get $app multisite)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
#=================================================
# FIX OLD THINGS
#=================================================
if [ -z "$admin_wordpress" ]; then
ynh_mysql_execute_as_root "select MAX(user_login) from wp_users where user_status=0 INTO OUTFILE '/tmp/wordpressuser';" $db_name
admin_wordpress=$(cat /tmp/wordpressuser)
sudo rm -f /tmp/wordpressuser
ynh_app_setting_set $app admin $admin_wordpress
fi
if [ -z "$final_path" ]; then
final_path=/var/www/$app
ynh_app_setting_set $app final_path $final_path
fi
if [ -z "$language" ]; then
language=$(sudo grep WPLANG $final_path/wp-config.php | cut -d"'" -f4)
ynh_app_setting_set $app language $language
fi
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1 # Fixe is_public en booléen
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0
is_public=0
fi
if [ "$multisite" = "Yes" ]; then
ynh_app_setting_set $app multisite 1 # Fixe multisite en booléen
multisite=1
elif [ "$multisite" = "No" ]; then
ynh_app_setting_set $app multisite 0
multisite=0
fi
if [ -z $db_name ]; then # Si db_name n'est pas renseigné dans app setting
db_name=$(ynh_make_valid_dbid $app)
ynh_app_setting_set $app db_name $db_name
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
BACKUP_BEFORE_UPGRADE # Backup the current version of the app
ynh_clean_setup () {
BACKUP_FAIL_UPGRADE # restore it if the upgrade fails
}
ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée.
#=================================================
# CHECK THE PATH
#=================================================
path_url=$(ynh_normalize_url_path $path_url) # Vérifie et corrige la syntaxe du path.
#=================================================
# NGINX CONFIGURATION
#=================================================
# Copie le fichier de config nginx
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
# Modifie les variables dans le fichier de configuration nginx
sudo sed -i "s@__PATHTOCHANGE__@$path_url@g" /etc/nginx/conf.d/$domain.d/$app.conf
sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/nginx/conf.d/$domain.d/$app.conf
sudo sed -i "s@__NAMETOCHANGE__@$app@g" /etc/nginx/conf.d/$domain.d/$app.conf
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_system_user_create $app # Create the dedicated user, if not exist
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
POOL_FPM # Créer le fichier de configuration du pool php-fpm et le configure.
#=================================================
# SPECIFIC UPGRADE
#=================================================
# SAVE THE CONFIG FILE IF IT BEEN MODIFIED
#=================================================
CHECK_MD5_CONFIG "wp-config.php" "$final_path/wp-config.php" # Créé un backup du fichier de config si il a été modifié.
#=================================================
# CONFIGURE MULTISITE
#=================================================
if [ $multisite -eq 1 ]
then
sudo sed -i "s@#--MULTISITE--@@g" /etc/nginx/conf.d/$domain.d/$app.conf
else
multisite=0
if [ $is_public -eq 0 ]
then
sudo sed -i "s@#--PRIVATE--@@g" /etc/nginx/conf.d/$domain.d/$app.conf
else
sudo sed -i "s@//--PUBLIC--define@define@g" $final_path/wp-config.php
fi
fi
ynh_app_setting_set $app multisite $multisite
#=================================================
# STORE THE CHECKSUM OF THE CONFIG FILE
#=================================================
STORE_MD5_CONFIG "wp-config.php" "$final_path/wp-config.php" # Réenregistre la somme de contrôle du fichier de config
#=================================================
# GENERIC FINALISATION
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
# Les fichiers appartiennent à l'user wordpress, pour permettre les mises à jour.
sudo chown -R $app: $final_path
# Sauf le fichier de config wp-config.php qui appartient à root
sudo chown root: $final_path/wp-config.php
#=================================================
# SETUP SSOWAT
#=================================================
ynh_app_setting_delete $app skipped_uris # Retire le skipped_uris si il existe encore.
if [ $is_public -eq 0 ]; then # Retire l'accès public
ynh_app_setting_delete $app unprotected_uris
else # Ou remplace le skipped_uris par unprotected_uris le cas échéant.
ynh_app_setting_set $app unprotected_uris "/"
fi
#=================================================
# RELOAD NGINX
#=================================================
sudo systemctl reload nginx